Part VI. Reliability and Fault Tolerance · Chapter 48
Repetition, Bit-Flip, Phase-Flip, and Shor Codes
Before arguing about surface codes and thresholds, you need one code you can trace by hand. This chapter walks the smallest real examples — repetition, bit-flip, phase-flip, and Shor's nine-qubit construction — until encode, corrupt, syndrome, recover is mechanical.
In this chapter 16 sections
The three-qubit repetition code separates one X error by parity, the phase-flip code conjugates the same construction with Hadamards to separate Z errors, and Shor's nine-qubit code concatenates the two so arbitrary single-qubit Pauli errors are diagnosable under ideal extraction.
These codes illustrate exact single-error correction, not modern overhead, threshold, repeated noisy extraction, or useful fault tolerance. The phrase majority vote is used only for the classical parity pattern; logical amplitudes are never copied or measured directly.
The repetition code promises one X error
State codewords, correctable error set, stabilizers, and failure for two flips before presenting recovery.
Small codes are teaching instruments. They show redundancy, syndrome extraction, and recovery working against a limited error set — concretely enough to simulate in your head. They cannot prove a scalable machine, but they make the logic of quantum error correction mechanical instead of mystical.
The three-qubit repetition construction corrects a single bit flip but not arbitrary single-qubit errors. [nielsen-chuang][preskill-notes]
The three-qubit promise is deliberately narrow
The bit-flip code uses and , with stabilizers Z0Z1 and Z1Z2. Its ideal recovery contract covers I and one X on any physical qubit. It also preserves an arbitrary encoded superposition because parity checks reveal only which block parity changed, not whether the logical component was zero or one.
This is not cloning. Encoding maps one input qubit plus initialized ancillas through a unitary into . It does not create , whose expansion contains six additional basis terms. The encoded state has one logical degree of freedom distributed nonlocally.
Enumerate the eight promised basis cases
For logical zero, no error and X0, X1, X2 produce 000, 100, 010, and 001. Their syndromes 00, 10, 11, and 01 select no correction, X0, X1, and X2, returning 000. For logical one, the corresponding words 111, 011, 101, and 110 produce the same syndrome sequence and return 111. Recovery is independent of the logical value.
Generate those rows rather than hand-copying them. The executable fixture computes parity bits, chooses a correction, applies it, and asserts equality with the original codeword. A second assertion checks that syndrome labels agree with the operator derivation from Chapter 47. This catches a decoder table that is self-consistent but wired to reversed check order.
Eight truth-table rows verify the promise
Generate no-error and every single-flip case for logical zero and one from the companion model.
The three-qubit bit-flip code encodes and . An arbitrary logical state becomes . Note what this is not: three copies of , which the no-cloning theorem forbids. It is a single entangled state spread across the register. A single bit flip moves the state out of the code space in a way a syndrome can identify.
Phase-flip protection follows from changing basis with Hadamard operations around a repetition construction. [nielsen-chuang]
Make the uncorrectable case visible
Start with logical zero and apply X0X1, producing 110. Its syndrome is 01, the same signature that a single X2 creates on a valid codeword. The minimum-weight decoder therefore applies X2 and obtains 111: a valid codeword carrying the wrong logical value. The recovery did exactly what its error model prescribed; the actual error lay outside that model.
Every weight-two bit-flip pattern has the same ambiguity with the complementary weight-one pattern. Majority decoding expresses the result classically, but the operator statement is more precise: the product of actual error and chosen recovery is X0X1X2, the logical X operator. A wrong decode can return to the code space, so “all checks are +1” after recovery does not prove the logical state is correct.
Hadamards rotate phase errors into bit errors
Trace the basis change and preserve the distinction between X and Z channels.
The error model comes first. The bit-flip channel is what the repetition code is built against, and the syndrome map turns each error pattern into a diagnostic signature.
Shor's nine-qubit scheme was an early code capable of correcting arbitrary single-qubit errors under its model. [shor-code-1995]
Hadamard conjugation builds phase-flip protection
Hadamard exchanges X and Z: and . Conjugating the repetition construction by H on all three qubits therefore turns a physical Z error in the original basis into an X error in the rotated basis. Run the same parity diagnosis there, apply the correction, and rotate back. The basis changes are part of the code definition, not optional visualization.
The phase-flip codewords can be written and under this convention. Measuring physical qubits directly in the X basis would reveal logical information; the extraction circuit instead measures the appropriate commuting X-type parities with ancillas.
A Y error is proportional to XZ and therefore carries both bit- and phase-error components. The three-qubit bit-flip code alone does not correct it, and the phase-flip code alone does not correct it. Correcting an arbitrary single-qubit Pauli requires a construction whose syndrome information distinguishes both components.
Shor concatenates protection in two directions
Describe the nine-qubit block structure and why X, Z, and Y single-qubit errors fit its ideal correctable set.
Bit-flip codes handle X -like errors. Phase-flip codes handle Z -like errors by the same construction in a rotated basis: Hadamard gates turn phase flips into bit flips, the repetition machinery catches them, and Hadamards turn back. Shor's nine-qubit code nests the two — a phase-flip triplet whose three branches are each bit-flip triplets — so any single-qubit error, X , Z , or Y (which acts as both), lands in a distinct syndrome. That nesting, not a bigger majority vote, is the idea that scales.
The Steane code provides a distinct seven-qubit stabilizer construction and should not be presented as a variant of Shor concatenation. [steane-code-1996][gottesman-stabilizer]
Shor concatenation separates both components
Shor’s code uses three GHZ-like blocks. One conventional expression is and . Within each block, Z-parity checks locate one X component. Comparisons across blocks diagnose the Z component through the outer phase-flip repetition structure.
An arbitrary single-qubit operator is a linear combination of I, X, Y, and Z. If the code corrects those Pauli actions on each location and the error-correction conditions hold, linearity extends correction to that arbitrary one-qubit error. The decoder does not need to know a continuous rotation angle; syndrome projection separates the relevant discrete error subspaces.
Y is not a third independent mystery: up to phase, Y=XZ. Its syndrome combines the bit- and phase-component signatures. The global phase attached to the Pauli product is unobservable, while the two syndrome components determine the recovery class.
Distance three sets the exact boundary
Connect correctable weight, distance, and the failure of ambiguous weight-two patterns.
Encode logical zero as . A bit flip strikes the second physical qubit, so the register reads . The parity checks report , the signature of a middle-qubit flip, and applying to that qubit returns the word to .
Code definitions alone do not satisfy the additional conditions required for fault-tolerant computation. [fault-tolerant-roads]
Distance three is the exact algebraic boundary
A distance-three code detects up to two errors in the operator sense and corrects an arbitrary error on at most location. Detection and correction are different promises. The selected weight-two repetition-code example is detectable relative to some codeword transitions but not uniquely correctable; the syndrome aliases a more likely single fault.
Error degeneracy can make different physical operators equivalent on the code space when they differ by a stabilizer. A decoder should reason about equivalence classes, not insist on reconstructing the literal microscopic fault. Success means the combined error and recovery acts trivially on logical information, not that every physical event was identified.
From code definition to fault-tolerant extraction
List ancilla, propagation, measurement, and repeated-cycle requirements intentionally absent here.
Now the important case: the superposition suffers the same flip and becomes . The same syndrome logic identifies the middle qubit, the same X repairs it, and α and β were never read. The correction acted on the error, not the data — which is the only way it can work.
The three-qubit repetition construction corrects a single bit flip but not arbitrary single-qubit errors. [nielsen-chuang][preskill-notes]
Ideal correction is not fault-tolerant extraction
The truth tables assume perfect encoding, ancillas, check gates, measurement, decoder, and recovery. In hardware, one ancilla fault can propagate through several data interactions; measurement errors can mimic data syndromes; and recovery pulses add faults. Repeated rounds and verified or carefully scheduled ancillas are needed to bound propagation.
Logical gates add another obligation. An operation must preserve the encoded computation and prevent one fault from spreading into an uncorrectable pattern within a block. The Shor code demonstrates that an arbitrary single physical-qubit error is correctable under ideal extraction; it does not by itself demonstrate a scalable gate set, threshold, useful logical lifetime, or competitive overhead.
The publishable small-code matrix therefore contains both green and red rows: every no-error and single-error case must recover, the chosen weight-two input must decode to the wrong logical value exactly as predicted, and phase cases must show both Hadamard layers. Hiding the red row would erase the code’s most important specification.
The matrix should separate detection, chosen recovery, final stabilizer signs, and logical outcome. The weight-two row is instructive because its final stabilizers return to +1 while its logical outcome flips. A pass/fail column based only on code-space membership would misclassify that row as corrected.
For phase protection, test more than basis labels. Start with , inject one Z, conjugate by H on all data qubits, run the bit-flip syndrome and recovery, then conjugate back. The output must match the encoded input up to a global phase for several analytic α,β choices. Testing only can conceal a relative-phase defect.
The Shor symbolic table should list, for each of nine locations, the syndrome class of X, Z, and Y rather than materializing a 512-amplitude state for every row. An independent small-state or stabilizer calculation can sample rows to verify the table. This keeps the artifact inspectable while still demonstrating that both error components are represented.
Error correction succeeds on spans of correctable errors, not merely a menu of named Paulis. If coherent error acts on one physical qubit, syndrome measurement projects the state into corresponding error subspaces and the conditioned recovery restores logical information when the code-correction conditions are satisfied. That is why discrete syndrome logic can address continuous small rotations without estimating their angle.
Recovery verification should compare logical states, not demand that every physical ancilla return to its initial value. Ancillas may be measured and reset, and stabilizer-equivalent physical states encode the same logical information. The contract names which registers are outputs, which are disposable syndrome workspace, and whether equality is exact or up to global phase.
Claim-to-source ledger
The three-qubit repetition construction corrects a single bit flip but not arbitrary single-qubit errors. [nielsen-chuang][preskill-notes]
Phase-flip protection follows from changing basis with Hadamard operations around a repetition construction. [nielsen-chuang]
Shor's nine-qubit scheme was an early code capable of correcting arbitrary single-qubit errors under its model. [shor-code-1995]
The Steane code provides a distinct seven-qubit stabilizer construction and should not be presented as a variant of Shor concatenation. [steane-code-1996][gottesman-stabilizer]
Code definitions alone do not satisfy the additional conditions required for fault-tolerant computation. [fault-tolerant-roads]
Small-code correctable-error matrix
Format: Reuse `error_correction.py`; extend fixtures to phase-flip basis-change cases and a symbolic Shor-code error-class table.
| input | output | reject when |
|---|---|---|
| assumptions, units, source/date, workload | raw and derived values, uncertainty, command | units or comparison scope are missing |
| synthetic fixture labeled synthetic | deterministic record and PASS line | attributed to real hardware |
| named baseline | same task and denominator | metric or evidence class differs |
def syndrome(qubit, pauli):
bit = tuple(int(i == qubit and pauli in "XY") for i in range(3))
phase = tuple(int(i == qubit and pauli in "ZY") for i in range(3))
parity = lambda v: (v[0] ^ v[1], v[1] ^ v[2])
return parity(bit), parity(phase)
def decode(bits):
return int(sum(bits) >= 2)
baseline = {(q, p): syndrome(q, p) for q in range(3) for p in "XYZ"}
counterfactual = decode((1, 1, 0))
single_x = [decode(tuple(logical ^ int(i == q) for i in range(3))) for logical in (0, 1) for q in range(3)]
assert single_x == [0, 0, 0, 1, 1, 1] and counterfactual == 1
assert all(baseline[q, "Y"] == (baseline[q, "X"][0], baseline[q, "Z"][1]) for q in range(3))
assert all(syndrome(q, "Z")[1] == syndrome(q, "X")[0] for q in range(3))
print(f"PASS: 48 code evidence classes={len(set(baseline.values()))} single_X={single_x} double_X={counterfactual}")
Verification: Existing single-bit test passes for both codewords; phase cases round-trip through H; every listed single-qubit Pauli maps to its declared syndrome class without measuring logical value.
Commissioned exercise
Prompt: Generate all no-error and single-X rows for both logical codewords, add one two-X error, and explain why the same syndrome causes a wrong correction.
Deliverable: Generated table, one ambiguous weight-two trace, phase-flip basis trace, and exact statement of each code's correctable set.
Pass condition: All single-X rows recover; the two-X row fails as predicted rather than being hidden; phase trace uses H before and after parity recovery.
Verifiable solution
Format: Reference tables and a short distance-three explanation.
Verification: Automated tests assert every single-error recovery and explicitly assert the selected weight-two failure.
Majority decoding returns the original logical value for every one-bit flip of 000 and 111. The explicit two-flip input 110 decodes as logical one when logical zero was sent, so the result records the promised uncorrectable boundary instead of hiding it.
Companion work
Artifacts for this chapter
These entries resolve to checked-in local source. Commands are reproduced exactly from the chapter manifest, and source-embedded fixtures are exported as direct downloads.
engineering fixture
Small-code correctable-error matrix
Reproduce or test
python3 tools/validate_briefs.py --briefs data/editorial_briefs_36_63.json --from 36 --through 63 --check-rewritten-sources --execute-artifacts
Provenance
Sources and review
- Michael A. Nielsen and Isaac L. Chuang. Quantum Computation and Quantum Information. Cambridge University Press. 2010textbook
- John Preskill. Lecture Notes for Physics 219: Quantum Computation. California Institute of Technology. 2018graduate lecture notes
- Peter W. Shor. Scheme for reducing decoherence in quantum computer memory. Physical Review A. 1995primary paper
- Andrew M. Steane. Error correcting quantum code. Physical Review Letters. 1996primary paper
- Daniel Gottesman. Stabilizer codes and quantum error correction. California Institute of Technology / arXiv. 1997doctoral thesis
- Earl T. Campbell, Barbara M. Terhal, and Christophe Vuillot. Roads towards fault-tolerant universal quantum computation. Nature. 2017peer-reviewed review
The load-bearing claims in the chapter are mapped inline to this registered source set. A citation supports only the bounded claim beside it.