4. The GHZ state
The Bell state correlates two qubits. The GHZ state correlates three: one
Hadamard and two CNOTs produce a state that is only ever measured as 000 or
111.
1. The idea
Copy the superposition on qubit 0 onto qubit 1, then onto qubit 2. Each CNOT
flips its target only in the branch where the control is 1, so the three
bits stay equal.
2. The code
import numpy as np
from fqkit import QuantumCircuit, Hadamard, CNOT, run, measure_all
np.set_printoptions(precision=4, suppress=True)
qc = QuantumCircuit(3)
qc.add_gate(Hadamard(), [0])
qc.add_gate(CNOT(), [0, 1])
qc.add_gate(CNOT(), [0, 2])
state = run(qc)
print("Probabilities:", np.round(np.abs(state) ** 2, 4))
print("Counts :", measure_all(state, shots=1024))3. The output
Probabilities: [0.5 0. 0. 0. 0. 0. 0. 0.5]
Counts : {'000': 499, '111': 525}Eight amplitudes, two of them nonzero. They are the first entry (000) and
the last (111). The counts move around 512 / 512; the zeros do not.
4. The explanation
- Hadamard on qubit 0 creates the branches
000and100. - CNOT from 0 to 1 turns
100into110. - CNOT from 0 to 2 turns
110into111. - The
000branch is never flipped. No amplitude is left on001,010,011,100,101, or110. - Any one qubit, looked at alone, is random. Any two already determine the third.
5. The math
In fqkit’s big endian order the vector has length 8:
💡
Key insight: adding a qubit did not add a new independent coin. Both CNOTs copy the same superposition, so the only surviving outcomes are the two in which every bit agrees.
Try it yourself
- Drop the second CNOT. Which two bitstrings remain, and which qubit is now independent?
- Change the second CNOT to
[1, 2]. Is the final state the same GHZ state? - The algorithms that use these states are in Algorithms, starting with Deutsch’s algorithm.
Last updated on