Shor's code is the first quantum error correcting code (1995), proving that quantum information can be protected despite the no-cloning theorem. It encodes 1 logical qubit into 9 physical qubits and corrects any single-qubit error — X, Y, or Z — using a concatenated structure of bit-flip and phase-flip codes.
- First complete QEC code — proved quantum error correction is possible
- Overcame the no-cloning barrier — you can protect quantum information without copying it
- Foundation for fault tolerance — showed quantum computers can work reliably
- Led directly to the threshold theorem: if physical error rates are low enough, arbitrary-length quantum computation is possible
The code has two levels:
Logical qubit
│
▼
┌────────────────────────────────────────┐
│ Outer Phase-Flip Code (3 blocks) │
│ │
│ Block 0 Block 1 Block 2 │
│ ┌──────┐ ┌──────┐ ┌──────┐ │
│ │ q0 │ │ q3 │ │ q6 │ │
│ │ q1 │ │ q4 │ │ q7 │ │
│ │ q2 │ │ q5 │ │ q8 │ │
│ │ │ │ │ │ │ │
│ │ Inner │ │ Inner │ │ Inner │ │
│ │Bit-Flip│ │Bit-Flip│ │Bit-Flip│ │
│ └──────┘ └──────┘ └──────┘ │
└────────────────────────────────────────┘
| Logical | Encoded State |
|---|
| |0>_L | (|000> + |111>)(|000> + |111>)(|000> + |111>) / 2*sqrt(2) |
| |1>_L | (|000> - |111>)(|000> - |111>)(|000> - |111>) / 2*sqrt(2) |
Phase-flip Bit-flip (per block)
┌───────────┐ ┌──────────────────┐
q_0: ──■────■──┤ H ├───────■────■──
│ │ └───┘ ┌─┴─┐ │
q_1: ──┼────┼─────────────┤ X ├──┼──
│ │ └───┘┌─┴─┐
q_2: ──┼────┼──────────────────┤ X ├
┌─┴─┐ │ ┌───┐
q_3: ┤ X ├──┼──┤ H ├─────■────■──
└───┘ │ └───┘ ┌─┴─┐ │
q_4: ───────┼───────────┤ X ├──┼──
│ └───┘┌─┴─┐
q_5: ───────┼────────────────┤ X ├
┌─┴─┐ ┌───┐
q_6: ─────┤ X ├─┤ H ├───■────■──
└───┘ └───┘ ┌─┴─┐ │
q_7: ──────────────────┤ X ├──┼──
└───┘┌─┴─┐
q_8: ───────────────────────┤ X ├
└───┘
- Detected within each 3-qubit block by the inner bit-flip code
- Same mechanism as the standalone 3-qubit bit-flip code
- Corrected with conditional X gate on the affected qubit
- Changes the relative sign between |000> and |111> within a block
- Detected across blocks by the outer phase-flip code
- Corrected with conditional Z gate on any qubit in the affected block
- Y = iXZ — both a bit-flip AND a phase-flip simultaneously
- The X component is caught by the inner code
- The Z component is caught by the outer code
- Both corrections applied independently
| Block | Syndrome | Error Location |
|---|
| 0 | 00 | No error in {q0, q1, q2} |
| 0 | 01 | q2 |
| 0 | 10 | q0 |
| 0 | 11 | q1 |
| 1 | 00 | No error in {q3, q4, q5} |
| 1 | 01 | q5 |
| 1 | 10 | q3 |
| 1 | 11 | q4 |
| 2 | 00 | No error in {q6, q7, q8} |
| 2 | 01 | q8 |
| 2 | 10 | q6 |
| 2 | 11 | q7 |
| Syndrome | Error Location |
|---|
| 00 | No phase error |
| 01 | Block 2 |
| 10 | Block 0 |
| 11 | Block 1 |
from circuit import run_circuit, verify_shor_code
# No error
result = run_circuit()
print(f"Success: {result['success_rate']:.2%}")
# X error on qubit 4 (middle of block 1)
result = run_circuit(error_type='X', error_qubit=4)
print(f"After X correction: {result['success_rate']:.2%}")
# Y error (both X and Z)
result = run_circuit(error_type='Y', error_qubit=2)
print(f"After Y correction: {result['success_rate']:.2%}")
# Full verification
v = verify_shor_code()
for check in v["checks"]:
print(f"[{'PASS' if check['passed'] else 'FAIL'}] {check['name']}")
| Property | Value |
|---|
| Notation | [[9, 1, 3]] |
| Physical qubits | 9 |
| Logical qubits | 1 |
| Code distance | 3 |
| Correctable errors | t = 1 (any type) |
| Rate | 1/9 ~ 0.111 |
| Syndrome qubits | 8 (6 bit-flip + 2 phase-flip) |
| Total qubits | 17 |
| Code | Notation | Qubits | Rate | Corrects | Structure |
|---|
| Bit-flip | [[3,1,3]] | 3 | 1/3 | X only | Repetition |
| Phase-flip | [[3,1,3]] | 3 | 1/3 | Z only | Hadamard repetition |
| Shor | [[9,1,3]] | 9 | 1/9 | X, Y, Z | Concatenated |
| Steane | [[7,1,3]] | 7 | 1/7 | X, Y, Z | CSS (Hamming) |
| Surface | [[d^2,1,d]] | d^2 | 1/d^2 | X, Y, Z | Topological |