The Three-Qubit Phase-Flip Code
By working in the Hadamard basis, the three-qubit code corrects a single phase flip instead of a bit flip.
Encoding in the conjugate basis
The phase-flip code is the bit-flip code viewed through Hadamard gates. Its logical states are |0_L> = |+++> and |1_L> = |--->, where |+> and |-> are the eigenstates of X. Encoding first builds |000> or |111> as before, then applies a Hadamard to each qubit.
# Encode into the +/- basis
circuit.cx(0, 1)
circuit.cx(0, 2)
circuit.h(0); circuit.h(1); circuit.h(2)
Because HZH = X, a phase flip Z on a physical qubit looks like a bit flip in the |+>, |-> basis. The code that detected bit flips now detects phase flips.
Syndrome measurement
The parity checks become X0 X1 and X1 X2. These measure whether neighboring qubits agree in the Hadamard basis, and their outcomes locate a single Z error just as Z Z parities located an X error. Applying Z to the flagged qubit corrects it.
| X0X1 | X1X2 | error |
|---|---|---|
| + | + | none |
| - | + | qubit 0 |
| - | - | qubit 1 |
| + | - | qubit 2 |
- Logical states |+++> and |---> have distance 3 against Z errors.
- Stabilizers are X0X1 and X1X2 instead of Z0Z1 and Z1Z2.
- Corrects any single phase flip, but offers no protection against bit flips.
The symmetry between this code and the bit-flip code is exactly the X-Z duality. Neither alone is a full quantum code, but nesting one inside the other corrects both error types. That nesting is the Shor code, the first code able to correct an arbitrary single-qubit error.