Quantum Gates Cheat Sheet with Dirac Notation

Below is a comprehensive quantum cheat sheet from research thus far - that includes the matrix representation of each gate and the Dirac notation representation. The existing information has been supplemented with the Dirac notation to create the Dirac-Rosetta stone.

Sources : (unoffical citations)**

1. Medium.com Introduction to Quantum Computing by Chrs Ferrie : https://csferrie.medium.com/introduction-to-quantum-computing-49b31b96e70f

2. IBM qiskit documentation

3. Guido Fano • S.M. Blinder; “Twenty-First Century Quantum Mechanics: Hilbert Space to Quantum Computers Mathematical Methods and Conceptual Foundations”

4. https://www.uts.edu.au/our-research-archived/centre-quantum-software-and-information

5. https://www.csferrie.com/

Single-Qubit Gates

  1. Pauli-X (X) Gate:
    • Matrix: \(\begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\)
    • Dirac Notation: \[ X|0\rangle = |1\rangle, \quad X|1\rangle = |0\rangle \]
  2. Pauli-Y (Y) Gate:
    • Matrix: \(\begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix}\)
    • Dirac Notation: \[ Y|0\rangle = i|1\rangle, \quad Y|1\rangle = -i|0\rangle \]
  3. Pauli-Z (Z) Gate:
    • Matrix: \(\begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}\)
    • Dirac Notation: \[ Z|0\rangle = |0\rangle, \quad Z|1\rangle = -|1\rangle \]
  4. Hadamard (H) Gate:
    • Matrix: \(\frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}\)
    • Dirac Notation: \[ H|0\rangle = \frac{1}{\sqrt{2}}(|0\rangle + |1\rangle), \quad H|1\rangle = \frac{1}{\sqrt{2}}(|0\rangle - |1\rangle) \]
  5. Phase (S) Gate:
    • Matrix: \(\begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix}\)
    • Dirac Notation: \[ S|0\rangle = |0\rangle, \quad S|1\rangle = i|1\rangle \]
  6. \(\pi/8\) (T) Gate:
    • Matrix: \(\begin{pmatrix} 1 & 0 \\ 0 & e^{i\pi/4} \end{pmatrix}\)
    • Dirac Notation: \[ T|0\rangle = |0\rangle, \quad T|1\rangle = e^{i\pi/4}|1\rangle \]

Two-Qubit Gates

  1. Controlled-NOT (CNOT) Gate:
    • Matrix: \(\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix}\)
    • Dirac Notation: \[ \text{CNOT}|00\rangle = |00\rangle, \quad \text{CNOT}|01\rangle = |01\rangle \] \[ \text{CNOT}|10\rangle = |11\rangle, \quad \text{CNOT}|11\rangle = |10\rangle \]
  2. Controlled-Z (CZ) Gate:
    • Matrix: \(\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{pmatrix}\)
    • Dirac Notation: \[ \text{CZ}|00\rangle = |00\rangle, \quad \text{CZ}|01\rangle = |01\rangle \] \[ \text{CZ}|10\rangle = |10\rangle, \quad \text{CZ}|11\rangle = -|11\rangle \]
  3. SWAP Gate:
    • Matrix: \(\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\)
    • Dirac Notation: \[ \text{SWAP}|00\rangle = |00\rangle, \quad \text{SWAP}|01\rangle = |10\rangle \] \[ \text{SWAP}|10\rangle = |01\rangle, \quad \text{SWAP}|11\rangle = |11\rangle \]

Three-Qubit Gates

  1. Toffoli (CCNOT) Gate:
    • Matrix: \(\begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \end{pmatrix}\)
    • Dirac Notation: \[ \text{Toffoli}|abc\rangle = |ab, c \oplus (a \land b)\rangle \] where \(\oplus\) is the XOR operation and \(\land\) is the AND operation.

Here is what I’ve compiled so far into a complete cheat sheet with all the gates, including their matrix and Dirac notation representations:

Quantum Gate Cheat Sheet (Extended with Dirac Notation)

Operator Gate(s) Matrix Dirac Notation
Pauli-X (X) X \(\begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\) \(X|0\rangle = |1\rangle, \quad X|1\rangle = |0\rangle\)
Pauli-Y (Y) Y \(\begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix}\) \(Y|0\rangle = i|1\rangle, \quad Y|1\rangle = -i|0\rangle\)
Pauli-Z (Z) Z \(\begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}\) \(Z|0\rangle = |0\rangle, \quad Z|1\rangle = -|1\rangle\)
Hadamard (H) H \(\frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}\) \(H|0\rangle = \frac{1}{\sqrt{2}}(|0\rangle + |1\rangle)\) \(|1\rangle = \frac{1}{\sqrt{2}}(|0\rangle - |1\rangle)\)
Phase (S, P) S \(\begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix}\) \(S|0\rangle = |0\rangle, \quad S|1\rangle = i|1\rangle\)
\(\pi/8\) (T) T \(\begin{pmatrix} 1 & 0 \\ 0 & e^{i\pi/4} \end{pmatrix}\) \(T|0\rangle = |0\rangle, \quad T|1\rangle = e^{i\pi/4}|1\rangle\)
CNOT CNOT, CX \(\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix}\) \(\text{CNOT}|00\rangle = |00\rangle, \quad \text{CNOT}|01\rangle = |01\rangle\) (

, |11= |10) | | Controlled-Z | CZ | \(\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{pmatrix}\) | \(\text{CZ}|00\rangle = |00\rangle, \quad \text{CZ}|01\rangle = |01\rangle\) \(\text{CZ}|10\rangle = |10\rangle, \quad \text{CZ}|11\rangle = -|11\rangle\) | | SWAP | SWAP | \(\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\) | \(\text{SWAP}|00\rangle = |00\rangle, \quad \text{SWAP}|01\rangle = |10\rangle\) \(\text{SWAP}|10\rangle = |01\rangle, \quad \text{SWAP}|11\rangle = |11\rangle\) | | Toffoli | CCNOT, CCX, TOFF | \(\begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \end{pmatrix}\) | \(\text{Toffoli}|abc\rangle = |ab, c \oplus (a \land b)\rangle\) |

This table includes the operators, gates, matrix representations, and Dirac notation for common quantum gates, providing a comprehensive reference for quantum computation.

Quantum Gates Cheat Sheet with Dirac Notation:

Another guide that presents various quantum gates with both their matrix representation and their description in Dirac notation. The aim is to have a quick reference for understanding how these gates function mathematically and in terms of quantum states.

Single-Qubit Gates:

  1. Pauli-X (X) Gate:
    • Matrix:

      [0 1]
      [1 0]
    • Dirac Notation:

      • \(X \left| 0 \right> = \left| 1 \right>\)
      • \(X \left| 1 \right> = \left| 0 \right>\)
    • This gate flips the state of a qubit, transforming \(\left| 0 \right>\) to \(\left| 1 \right>\) and vice versa.

  2. Pauli-Y (Y) Gate:
    • Matrix:

      [ 0 -i]
      [ i  0]
    • Dirac Notation:

      • \(Y \left| 0 \right> = i \left| 1 \right>\)
      • \(Y \left| 1 \right> = -i \left| 0 \right>\)
    • This gate adds a phase of \(i\) (the imaginary unit).

  3. Pauli-Z (Z) Gate:
    • Matrix:

      [ 1  0]
      [ 0 -1]
    • Dirac Notation:

      • \(Z \left| 0 \right> = \left| 0 \right>\)
      • \(Z \left| 1 \right> = -\left| 1 \right>\)
    • This gate adds a phase of \(-1\) to the \(\left| 1 \right>\) state.

  4. Hadamard (H) Gate:
    • Matrix:

      1/sqrt(2) * [1  1]
                   [1 -1]
    • Dirac Notation:

      • \(H \left| 0 \right> = (1/sqrt(2)) (\left| 0 \right> + \left| 1 \right>)\)
      • \(H \left| 1 \right> = (1/sqrt(2)) (\left| 0 \right> - \left| 1 \right>)\)
    • This gate creates superposition states.

  5. Phase (S) Gate:
    • Matrix:

      [1 0]
      [0 i]
    • Dirac Notation:

      • \(S \left| 0 \right> = \left| 0 \right>\)
      • \(S \left| 1 \right> = i \left| 1 \right>\)
    • This gate adds a phase of \(i\) to the \(\left| 1 \right>\) state.

  6. \(\pi/8\) (T) Gate:
    • Matrix:

      [1   0]
      [0 exp(i*pi/4)]
    • Dirac Notation:

      • \(T \left| 0 \right> = \left| 0 \right>\)
      • \(T \left| 1 \right> = exp(i*pi/4) \left| 1 \right>\)
    • This gate adds a phase of \(e^{i\pi/4}\) to the \(\left| 1 \right>\) state.

Two-Qubit Gates:

  1. Controlled-NOT (CNOT) Gate:
    • Matrix:

      [1 0 0 0]
      [0 1 0 0]
      [0 0 0 1]
      [0 0 1 0]
    • Dirac Notation:

      • \(CNOT \left| 00 \right> = \left| 00 \right>\)
      • \(CNOT \left| 01 \right> = \left| 01 \right>\)
      • \(CNOT \left| 10 \right> = \left| 11 \right>\)
      • \(CNOT \left| 11 \right> = \left| 10 \right>\)
    • This gate flips the state of the target qubit if the control qubit is \(\left| 1 \right>\).

  2. Controlled-Z (CZ) Gate:
    • Matrix:

      [1 0 0 0]
      [0 1 0 0]
      [0 0 1 0]
      [0 0 0 -1]
    • Dirac Notation:

      • \(CZ \left| 00 \right> = \left| 00 \right>\)
      • (CZ | 01 > = |

Code 4 Qiskit:

Setting Up Qiskit

pip install qiskit

Then, import the necessary modules:

from qiskit import QuantumCircuit, Aer, transpile, assemble, execute
from qiskit.visualization import plot_histogram
import matplotlib.pyplot as plt

Single-Qubit Gates

  1. Pauli-X (X) Gate:
qc = QuantumCircuit(1)
qc.x(0)
qc.draw()
  1. Pauli-Y (Y) Gate:
qc = QuantumCircuit(1)
qc.y(0)
qc.draw()
  1. Pauli-Z (Z) Gate:
qc = QuantumCircuit(1)
qc.z(0)
qc.draw()
  1. Hadamard (H) Gate:
qc = QuantumCircuit(1)
qc.h(0)
qc.draw()
  1. Phase (S) Gate:
qc = QuantumCircuit(1)
qc.s(0)
qc.draw()
  1. \(\pi/8\) (T) Gate:
qc = QuantumCircuit(1)
qc.t(0)
qc.draw()

Two-Qubit Gates

  1. Controlled-NOT (CNOT) Gate:
qc = QuantumCircuit(2)
qc.cx(0, 1)
qc.draw()
  1. Controlled-Z (CZ) Gate:
qc = QuantumCircuit(2)
qc.cz(0, 1)
qc.draw()
  1. SWAP Gate:
qc = QuantumCircuit(2)
qc.swap(0, 1)
qc.draw()

Three-Qubit Gates

  1. Toffoli (CCNOT) Gate:
qc = QuantumCircuit(3)
qc.ccx(0, 1, 2)
qc.draw()

Running a Quantum Circuit

Here is an example of creating a quantum circuit with multiple gates and running it on a simulator:

qc = QuantumCircuit(3, 3)  # 3 qubits and 3 classical bits

# Apply gates
qc.h(0)  # Hadamard on qubit 0
qc.cx(0, 1)  # CNOT gate with control qubit 0 and target qubit 1
qc.ccx(0, 1, 2)  # Toffoli gate with control qubits 0, 1 and target qubit 2

# Measure all qubits
qc.measure([0, 1, 2], [0, 1, 2])

# Draw the circuit
print(qc.draw())

# Use Aer's qasm_simulator
simulator = Aer.get_backend('qasm_simulator')

# Compile and run the quantum circuit on the qasm simulator
compiled_circuit = transpile(qc, simulator)
qobj = assemble(compiled_circuit)
result = execute(qc, backend=simulator, shots=1024).result()

# Get the results of the computation
counts = result.get_counts(qc)
print("\nTotal count for 000 and 111 are:",counts)

# Plot a histogram
plot_histogram(counts)
plt.show()

Qiskit code to create a quantum circuit, apply a series of gates, measure the qubits, run the circuit on a quantum simulator, and visualize the results.