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.
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
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.
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.
Matrix:
[0 1]
[1 0]
Dirac Notation:
This gate flips the state of a qubit, transforming \(\left| 0 \right>\) to \(\left| 1 \right>\) and vice versa.
Matrix:
[ 0 -i]
[ i 0]
Dirac Notation:
This gate adds a phase of \(i\) (the imaginary unit).
Matrix:
[ 1 0]
[ 0 -1]
Dirac Notation:
This gate adds a phase of \(-1\) to the \(\left| 1 \right>\) state.
Matrix:
1/sqrt(2) * [1 1]
[1 -1]
Dirac Notation:
This gate creates superposition states.
Matrix:
[1 0]
[0 i]
Dirac Notation:
This gate adds a phase of \(i\) to the \(\left| 1 \right>\) state.
Matrix:
[1 0]
[0 exp(i*pi/4)]
Dirac Notation:
This gate adds a phase of \(e^{i\pi/4}\) to the \(\left| 1 \right>\) state.
Matrix:
[1 0 0 0]
[0 1 0 0]
[0 0 0 1]
[0 0 1 0]
Dirac Notation:
This gate flips the state of the target qubit if the control qubit is \(\left| 1 \right>\).
Matrix:
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 -1]
Dirac Notation:
Code 4 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
qc = QuantumCircuit(1)
qc.x(0)
qc.draw()
qc = QuantumCircuit(1)
qc.y(0)
qc.draw()
qc = QuantumCircuit(1)
qc.z(0)
qc.draw()
qc = QuantumCircuit(1)
qc.h(0)
qc.draw()
qc = QuantumCircuit(1)
qc.s(0)
qc.draw()
qc = QuantumCircuit(1)
qc.t(0)
qc.draw()
qc = QuantumCircuit(2)
qc.cx(0, 1)
qc.draw()
qc = QuantumCircuit(2)
qc.cz(0, 1)
qc.draw()
qc = QuantumCircuit(2)
qc.swap(0, 1)
qc.draw()
qc = QuantumCircuit(3)
qc.ccx(0, 1, 2)
qc.draw()
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.