The Four Bell States
Build all four Bell states with one parameterised construction (X before, Z after entangling) and print their amplitudes.
The four Bell states form an orthonormal basis for the two-qubit space, and all are maximally entangled: $|\Phi^\pm\rangle=(|00\rangle\pm|11\rangle)/\sqrt2$ and $|\Psi^\pm\rangle=(|01\rangle\pm|10\rangle)/\sqrt2$. All are prepared from $|00\rangle$: an X on $q_1$ (optional) sets the parity, then H and CNOT, then a Z on $q_0$ (optional) sets the sign.
The printed amplitudes are keyed in the order $q_1q_0$. For $\Psi^-$ this construction gives $(-|01\rangle+|10\rangle)/\sqrt2$, i.e. the textbook state multiplied by an unobservable global phase of $-1$.
Requirements: pip install qiskit qiskit-aer. The code runs on your machine or in Colab, not inside WordPress.
Code
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
def bell(z_bit, x_bit):
qc = QuantumCircuit(2)
if x_bit:
qc.x(1)
qc.h(0)
qc.cx(0, 1)
if z_bit:
qc.z(0)
return qc
names = {(0, 0): "Phi+", (1, 0): "Phi-", (0, 1): "Psi+", (1, 1): "Psi-"}
for (z, x), name in names.items():
sv = Statevector.from_instruction(bell(z, x))
amps = {str(k): round(float(v.real), 4) for k, v in sv.to_dict().items()}
print(name, amps)
Line-by-line code explanation
| Line | Explanation |
|---|---|
| 1-2 | Import the circuit and Statevector. |
| 5 | A function that builds a Bell state from two bits. |
| 6 | A two-qubit circuit. |
| 7-8 | X on q1 to choose the Ψ family. |
| 9-10 | H then CNOT to create entanglement. |
| 11-12 | Z on q0 to choose the negative sign. |
| 13 | Return the circuit. |
| 16 | Map each pair of bits to the state's name. |
| 17 | Loop over the four states. |
| 18 | Compute the state vector. |
| 19 | Convert it to a dictionary of rounded real amplitudes. |
| 20 | Print the name and the amplitudes. |
Expected output (from an actual run)
Phi+ {'00': 0.7071, '11': 0.7071}
Phi- {'00': 0.7071, '11': -0.7071}
Psi+ {'01': 0.7071, '10': 0.7071}
Psi- {'01': -0.7071, '10': 0.7071}
The output is deterministic.
Try it yourself
Related topics
References
- Michael A. Nielsen; Isaac L. Chuang (2010). Quantum Computation and Quantum Information (10th Anniversary Edition). Cambridge University Press doi:10.1017/CBO9780511976667The standard reference for quantum computing; the Crossref record gives 2012 for the Cambridge Core online edition.
- IBM Quantum (2025). Qiskit SDK API documentation. IBM Quantum Documentation quantum.cloud.ibm.com
