Correcting Arbitrary Single-Qubit Errors
The three-qubit bit-flip code corrects errors. To correct an arbitrary single-qubit error — any , , or — we need the structure of the Shor code. This lesson first shows the mechanics of a coherent correction on the small bit-flip code, then explains how the same idea scales to full Pauli protection.
Why correcting X, Z, and Y is enough
Recall the digitization principle: an arbitrary single-qubit error is a linear combination . Syndrome measurement projects the state onto one Pauli branch, so a code that handles , , and on every qubit handles all small errors. And since , a code that independently catches and catches for free — the error simply lights up both the bit-flip and phase-flip syndromes at once.
This is the design logic of the Shor code: its inner blocks correct on any qubit, its outer phase structure corrects on any block, and the combination corrects .
Coherent correction without measurement
We can recover a logical qubit using only unitary gates — no mid-circuit measurement, no classical feedback. The trick is to let the redundancy qubits control the correction directly:
- Decode. Apply the inverse encoder. For the bit-flip code the encoder is
cx(0,1); cx(0,2), and since CNOT is its own inverse, repeating it decodes. The logical amplitude gathers back onto the data qubit while qubits 1 and 2 are left holding the error syndrome. - Vote. A single Toffoli
ccx(2,1,0)flips the data qubit exactly when both partners read . For a single bit flip this is precisely the majority correction.
Walking the example
We encode , inject on qubit 1 (giving ), then decode and vote. The data qubit returns to ; qubits 1 and 2 are left in the syndrome state , which records "the middle qubit was hit." The grader checks the full three-qubit statevector, which is fully determined: two amplitudes of that differ only in the qubit-0 bit.
From bit-flip to arbitrary errors
To upgrade this to full single-qubit protection you wrap the bit-flip correction (run inside each of the three blocks) with an analogous phase correction across the blocks — exactly the nine-qubit Shor code. The block-level circuits detect ; transforming each block into the Hadamard basis turns a on that block into a detectable bit flip; and triggers both. The recovery is the corresponding product of and corrections.
Try it
Correct the injected bit-flip coherently: decode, then vote with a Toffoli. The grader checks the full statevector — qubit 0 must come back to .
After running, the two populated amplitudes are at indices 2 (010) and 6 (110), each
. They differ only in the qubit-0 bit, confirming the logical qubit is restored to
with the syndrome parked on qubits 1 and 2.
Sign in on the full site to ask questions and join the discussion.