The Three-Qubit Bit-Flip Code
The simplest quantum code encodes one qubit in three, detecting and correcting a single bit-flip by measuring two parity operators.
Encoding
The three-qubit bit-flip code maps the logical states to |0_L> = |000> and |1_L> = |111>, so a|0>+b|1> becomes a|000>+b|111>. Encoding uses two CNOT gates from the data qubit onto two fresh |0> ancillas. The result is entangled, not cloned, so the no-cloning theorem is respected.
# Encode a|0>+b|1> into a|000>+b|111>
# qubit 0 is data; 1,2 are ancillas in |0>
circuit.cx(0, 1)
circuit.cx(0, 2)
Syndrome measurement
To find a bit flip without collapsing the superposition, measure the two parity operators Z0 Z1 and Z1 Z2. Each returns +1 if the pair agrees and -1 if it disagrees, revealing the location of a disagreement but never the values a and b. The pair of outcomes is the syndrome.
| Z0Z1 | Z1Z2 | error |
|---|---|---|
| + | + | none |
| - | + | qubit 0 |
| - | - | qubit 1 |
| + | - | qubit 2 |
A single X on qubit i produces a unique syndrome, so majority-vote correction succeeds. If X hits qubit 0, qubits 0 and 1 disagree while 1 and 2 agree, giving (-,+). Applying X to the flagged qubit restores the codeword.
Limits
This code corrects any single bit flip and, by linearity, even a partial rotation about X, because the syndrome measurement projects the continuous error into either no-flip or full-flip. Its distance is 3 against X errors. But it offers no protection against phase flips: a Z on any of the three qubits commutes with the parity checks and passes undetected, in fact a single physical Z becomes a logical Z. Correcting phase errors requires the conjugate phase-flip code, and correcting both requires their concatenation, the Shor code.