Quantum Computing Master Course — 117. The Shor Code
Lesson 117: The Shor Code
Smartyfy Quantum Computing Master Course
Prerequisites and objectives
The nine-qubit Shor code combines bit-flip and phase-flip protection to correct an arbitrary error on one physical qubit. You will construct its logical states, identify its eight stabilizer generators, and follow a mixed bit-and-phase error through an ideal recovery.
Data order is |q8 q7 … q0⟩. Group the qubits into blocks A=(q8,q7,q6), B=(q5,q4,q3), and C=(q2,q1,q0). Corrections and checks in this lesson are ideal; a separate fault-tolerance analysis is needed when the recovery circuit itself can fail.
Build the code by combining two encodings
Define |G+⟩=(|000⟩+|111⟩)/√2 and |G−⟩=(|000⟩−|111⟩)/√2 for a three-qubit block. These two states are normalized and orthogonal.
Choose logical basis states |0L⟩=|G+⟩A|G+⟩B|G+⟩C and |1L⟩=|G−⟩A|G−⟩B|G−⟩C. The unknown logical state is α|0L⟩+β|1L⟩.
This construction can be understood as first applying the three-qubit phase-flip encoding α|+++⟩+β|−−−⟩, then replacing each outer qubit by a three-qubit bit-flip repetition block. The inner encoding maps |+⟩ to |G+⟩ and |−⟩ to |G−⟩.
The result stores one logical qubit in nine physical qubits. It is a coherent concatenated encoding, not nine independent copies of the input.
Six checks protect the block bit patterns
Within each block, the two Z-pair checks verify that its three computational labels agree. Ordered first are g1=Z8Z7, g2=Z7Z6, g3=Z5Z4, g4=Z4Z3, g5=Z2Z1, and g6=Z1Z0.
These checks have eigenvalue +1 on both |G+⟩ and |G−⟩. A single X within a block produces the same two-bit location syndrome derived for the repetition code.
The checks reveal which physical position has a bit-flip component without determining whether that block carries the plus or minus GHZ phase.
Two checks protect relative block phases
Define block operators XA=X8X7X6, XB=X5X4X3, and XC=X2X1X0. Each block operator has eigenvalue +1 on |G+⟩ and −1 on |G−⟩.
The final generators are g7=XA XB and g8=XB XC. Both have eigenvalue +1 on either logical basis state, because neighboring block signs agree.
A Z on any physical qubit within a block exchanges |G+⟩ and |G−⟩ for that block. It therefore creates a phase-label mismatch detected by these two X-type checks.
| Generator labels | Pauli checks | Role |
|---|---|---|
| g1,g2 | Z8Z7; Z7Z6 | Bit parity inside A |
| g3,g4 | Z5Z4; Z4Z3 | Bit parity inside B |
| g5,g6 | Z2Z1; Z1Z0 | Bit parity inside C |
| g7,g8 | XA XB; XB XC | Phase-label parity across blocks |
All eight generators commute. A within-block Z pair overlaps either relevant X-type generator on zero or two positions, so local anticommutations occur an even number of times.
The generators are independent, giving code dimension 2^(9−8)=2. This agrees with the two logical basis states constructed above.
Worked Y error in the middle block
Use syndrome order g1 through g8, with zero for +1 and one for −1. Suppose Y4 acts on the middle physical qubit of block B.
Y4 anticommutes with g3 and g4 because those checks contain Z4. It also anticommutes with g7 and g8 because both contain X4. It commutes with the other generators.
The complete syndrome is therefore 00110011: block B’s internal bit syndrome is 11, and the cross-block phase syndrome is also 11.
Apply X4 to remove the bit component. Since XY=iZ, the residual operation on the original code state is iZ4. The overall phase i has no physical consequence.
The phase syndrome identifies block B but not a unique position inside it. Choose Z5 as its phase correction. The total residual is iZ5Z4, which is i times stabilizer g3. Thus the logical state is restored up to an irrelevant overall phase.
Degeneracy is useful, not a decoding failure
Z5,Z4,Z3 all act identically on the Shor code space: each exchanges the two GHZ phase labels in block B. Their pairwise products are within-block Z stabilizers.
The decoder does not need to distinguish those physically different phase-error locations. Any representative Z in the identified block produces the same logical recovery.
This is a degenerate code: some distinct errors share a syndrome because their difference acts trivially on the code. That is different from two errors sharing a syndrome while differing by an undetected logical operation.
The stabilizer formalism makes the distinction precise. Multiplying by a stabilizer preserves the encoded state; multiplying by a nontrivial logical operator need not.
Scope of the single-qubit guarantee
The code corrects I, Xj, Yj, and Zj for any one position j through one common recovery. By the correctable-span result, it therefore corrects an arbitrary channel confined to one unknown physical qubit in the ideal model.
Some higher-weight patterns are also harmless or correctable. For example, a pair of Z errors within one block can be a stabilizer, and isolated X errors in different blocks can be corrected independently.
However, arbitrary two-qubit errors are not guaranteed. Two X errors in one block can be misidentified as the complementary single flip; the resulting three-X block operation is a logical phase change.
If independent physical error events occur with probability p on each of nine qubits, the probability of at least two events is 1−(1−p)^9−9p(1−p)^8. It is a conservative failure bound for a decoder guaranteed to correct every zero-or-one-event case, not automatically its exact failure probability for every noise model.
Logical operations and implementation cost
In the chosen logical basis, XA acts as logical Z: it gives +1 on |0L⟩ and −1 on |1L⟩. The operator Z8Z5Z2 acts as logical X by exchanging every block’s GHZ sign.
Both have weight three. The full code distance is three, and the next lessons will explain how distance is defined through the smallest nontrivial logical Pauli rather than the number of checks.
Eight stabilizer constraints do not imply eight effortless measurements. The six-body X checks need an extraction circuit, ancillas, and a strategy for avoiding dangerous error propagation. Code correctness alone does not make a naive circuit fault tolerant.
Four exercises with worked solutions
-
What phase-check syndrome g7,g8 follows a Z error anywhere in block A?
Solution. It anticommutes with XA XB but not XB XC, giving 10. The within-block Z checks remain unchanged.
-
Why may Z5 correct the phase component of a Y4 error?
Solution. After the X4 correction, the residual is iZ4. Multiplying by Z5 gives iZ5Z4=i g3, which acts as identity up to overall phase on every code state.
-
How many logical qubits do eight independent generators on nine physical qubits encode?
Solution. k=9−8=1, and the code space has dimension two. Redundancy supplies protected space, not extra copies of the logical qubit.
-
Does the probability of at least two physical events always equal the logical failure probability?
Solution. No. Some multi-event patterns are stabilizers or otherwise corrected. The expression is an upper bound under the stated single-event guarantee unless a specific noise and decoder analysis establishes equality.
Five explained multiple-choice questions
-
The chosen Shor logical zero is: A. Nine independent |0⟩ states only. B. Three |G−⟩ blocks. C. An equal superposition of three |G+⟩ blocks and three |G−⟩ blocks. D. Three |G+⟩ blocks.
Answer: D. The block GHZ signs carry the outer phase-code structure.
-
Its X-type cross-block checks detect: A. Individual computational data values. B. Mismatches between block GHZ phase labels. C. The full three-bit within-block X-error syndrome. D. Every phase-error location inside a block uniquely.
Answer: B. A phase error changes a block sign, while its exact within-block location can be degenerate.
-
Y4 has syndrome in order g1…g8: A. 00110011. B. 00000000. C. 11000010. D. 00001101.
Answer: A. The error flips both internal checks of block B and both cross-block X checks.
-
Distinct same-block Z errors can share a correctable syndrome because: A. Their probabilities must be equal. B. The syndrome apparatus failed. C. Their difference can be a stabilizer. D. All phase errors are global phases.
Answer: C. Equivalent action on the code removes the need to identify a unique physical representative.
-
The code’s ideal arbitrary-error guarantee covers: A. Any number of faulty qubits. B. Faulty extraction without further analysis. C. Only classical X errors. D. An arbitrary error confined to one physical qubit.
Answer: D. Correcting the full single-position Pauli family extends to its operator span.
Pitfalls and summary
Track block and generator order, distinguish phase-location degeneracy from logical ambiguity, and state the error-weight promise. The Shor construction protects against both bit and phase components, while realistic extraction and multi-error performance need separate analysis.
Primary sources and further study
These sources support the definitions and context. The numerical examples, exercises, and explanations here were prepared for this lesson. Research papers are optional advanced reading.