The Shor 9-qubit code, by concatenation (§Q Q5, E1) #
Category: 5-Empirical-QM. The last iconic empirical item
(specs/BACKLOG.md E1 / §Q Q5): the 9-qubit code that corrects an
arbitrary single-qubit Pauli error, built as the concatenation of the
two landed 3-qubit halves — the phase-flip code (PhaseFlip.lean) outside,
the bit-flip code (ThreeQubit.lean) inside.
Glossary: https://glossary.constraintsurfacedynamics.com/shor-code/
Plain-language, CSD-role and formal statements of the Shor code, with
this module as the Lean anchor. Kept symmetric by scripts/check-glossary.sh.
The combinator, and why 512 dimensions never appear entry-wise #
The E1 row recorded the obstacle as dimensional: entry-wise tactics do not
survive 2⁹ = 512. The route chosen here is the row's code-concatenation
combinator option. One structural lemma does all the lifting:
kron_mulVec/tel9_bkron_vkron— the block Kronecker action factorises,(A ⊗ B ⊗ C)(u ⊗ v ⊗ w) = (Au) ⊗ (Bv) ⊗ (Cw).
Every 9-qubit statement then reduces to the 8-dimensional block facts
(where fin_cases is viable and mostly already proven): the inner code's
stabiliser fixing and syndromes are ThreeQubit's lemmas applied to the
block states B± = |000⟩ ± |111⟩ = logical 1 (±1), and the outer code's
action rides two new 8-dim computations (tel_Xall_logical,
tel_Zin_logical). Nothing above 8 dimensions is ever proved entry-wise.
The code and its statements #
shorLogical a b = a·(B₊⊗B₊⊗B₊) + b·(B₋⊗B₋⊗B₋) (unnormalised
coefficients, as in the 3-qubit modules — every statement is linear).
- Codespace: all eight stabilisers fix
shorLogical—innerStab_fixes_shorLogical(the sixZ_iZ_jpairs, via the bit-flip code's fixing lemmas) andouterStab_fixes_shorLogical(the twoX^{⊗6}operators, viaB±being±1-eigenstates ofX^{⊗3}). - Syndromes: ★
innerStab_syndrome_X— a bit flip at inner positionjof blockstrips blocks's stabiliser pair with exactly the 3-qubit sign pattern (xSyndromeSign, injective:xSyndromeSign_injective), while every other-block inner stabiliser (innerStab_fixes_X_other) and both outer stabilisers (outerStab_fixes_X) read+1. ★outerStab_syndrome_Z— a phase flip anywhere in blockstrips the outer pair with the block pattern (zSyndromeSign, injective:zSyndromeSign_injective), independent of which qubit inside was hit, while every inner stabiliser reads+1(innerStab_fixes_Z). X errors trip only inner stabilisers and Z errors only outer ones, so the classes are separated by construction. - Corrections (★★ the headline set): for every block
s : Fin 3and inner positionj : Fin 3,shor_corrects_X— re-applying the identified bit flip restores the state;shor_corrects_Z_degenerate— applyingZto the first qubit of the identified block restores the state whichever qubit inside was hit: the code is degenerate, and the recovery needs only the block-level syndrome;shor_corrects_XZ— the composite errorX_j Z_j(Y up to phase) is corrected by composing the two recoveries. Withpauli_decomposition(ErrorDiscretization.lean: every 2×2 error is a combination ofI, X, Z, XZ), this is the discretised form of "corrects an arbitrary single-qubit error".
Honest scope #
Correctable set: single-qubit errors (one position, one block). No claim about two-error patterns, measurement dynamics (the syndrome extraction is the eigenvalue reading, as in the 3-qubit modules — the collapse half at 9 qubits is not restated), or fault tolerance. The syndrome lemmas give the eigenvalue table and the two injectivity facts; the full 28-row distinctness tabulation is their mechanical product and is not separately enumerated.
Cross-references: specs/future-work.md, specs/BACKLOG.md §Q (Q5) and
the E1 assessment row; three_qubit_corrects_single_bitflip,
syndromePF_Z1 (the phase-flip half), pauli_decomposition,
syndrome_collapse (SyndromeCollapse.lean, the 3-qubit collapse half).
Source #
Shor 1995; Nielsen–Chuang §10.2 (the 9-qubit code as concatenation).
The 9-qubit space and the block Kronecker combinator #
The inner-block index: one 3-qubit register.
Instances For
The 9-qubit Hilbert space, blocked as three 3-qubit registers.
Equations
Instances For
Three-fold block Kronecker product of 8×8 block operators.
Equations
- CSD.Empirical.QM.QEC.bkron A B C = Matrix.kroneckerMap (fun (x1 x2 : ℂ) => x1 * x2) A (Matrix.kroneckerMap (fun (x1 x2 : ℂ) => x1 * x2) B C)
Instances For
Three-fold block tensor of block vectors:
vkron u v w = u ⊗ v ⊗ w entry-wise on the blocked index.
Equations
- CSD.Empirical.QM.QEC.vkron u v w = ∑ p : CSD.Empirical.QM.QEC.I3 × CSD.Empirical.QM.QEC.I3 × CSD.Empirical.QM.QEC.I3, EuclideanSpace.single p (u.ofLp p.1 * v.ofLp p.2.1 * w.ofLp p.2.2)
Instances For
★ The combinator: the block Kronecker action factorises through the
block tensor — (A ⊗ B ⊗ C)(u ⊗ v ⊗ w) = (Au) ⊗ (Bv) ⊗ (Cw). The one
lemma that reduces every 512-dimensional statement to 8-dimensional block
facts.
The block-level facts (8-dimensional, fin_cases-viable) #
The block states B± = |000⟩ ± |111⟩: the bit-flip code's encodings of
|±⟩. Bp = logical 1 1.
Equations
Instances For
The all-block bit flip X^{⊗3} = X₁X₂X₃ — the outer code's stabiliser
factor on one block.
Equations
Instances For
X^{⊗3} swaps |000⟩ ↔ |111⟩: on the logical block it exchanges the
coefficients.
B₊ is a +1 eigenstate of X^{⊗3}.
B₋ is a −1 eigenstate of X^{⊗3}.
The inner-position phase flips (PhaseFlip.lean's Z₁, Z₂, Z₃), as a
Fin 3-indexed family.
Equations
Instances For
The inner-position bit flips (ThreeQubit.lean's X₁, X₂, X₃), as a
Fin 3-indexed family.
Equations
Instances For
The block phase-flip action: every single Z inside a block flips
the sign of the |111⟩ component — Z_j (a|000⟩ + b|111⟩) = a|000⟩ − b|111⟩,
the same action for all three positions j. The germ of the code's
degeneracy.
Block-level degeneracy: Z₁ Z_j fixes the logical block for every
j — the two sign flips cancel, so recovering with Z₁ corrects a Z
error at any inner position.
The 9-qubit operators: placement and the code space #
Place a block operator in slot s (identity on the other blocks).
Equations
- CSD.Empirical.QM.QEC.place 0 x✝ = CSD.Empirical.QM.QEC.bkron x✝ 1 1
- CSD.Empirical.QM.QEC.place 1 x✝ = CSD.Empirical.QM.QEC.bkron 1 x✝ 1
- CSD.Empirical.QM.QEC.place 2 x✝ = CSD.Empirical.QM.QEC.bkron 1 1 x✝
Instances For
The Shor logical state
a·(B₊ ⊗ B₊ ⊗ B₊) + b·(B₋ ⊗ B₋ ⊗ B₋) (unnormalised coefficients).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Block s's stabiliser pair member: Z₁Z₂ (t = 0) or Z₂Z₃
(t = 1).
Equations
Instances For
The six inner stabilisers: block s's pair, chosen by t.
Equations
Instances For
The two outer stabilisers: X^{⊗6} on blocks 1–2 (t = 0) and 2–3
(t = 1).
Equations
Instances For
The single-qubit bit-flip error at inner position j of block s.
Equations
Instances For
The single-qubit phase-flip error at inner position j of block s.
Equations
Instances For
The codespace: all eight stabilisers fix the logical state #
The six inner stabilisers fix shorLogical: within each block the
bit-flip code's stabilisers fix both B₊ and B₋ (they are logical
instances).
The two outer stabilisers fix shorLogical: B₊ is a +1 eigenstate
of X^{⊗3} and B₋ a −1 eigenstate, and each outer stabiliser touches
exactly two blocks, so the signs cancel.
Syndromes: the eigenvalue table #
The bit-flip syndrome signs: position j against the stabiliser pair,
exactly the 3-qubit code's table (−,+), (−,−), (+,−).
Equations
Instances For
The phase-flip block-syndrome signs: block s against the outer pair —
the same mirror table (−,+), (−,−), (+,−), now reading the block.
Instances For
The bit-flip syndrome pattern is injective: the pair of inner readings
identifies the position within the block. (The 3-qubit
three_qubit_syndromes_distinct, at the level of the sign table.)
The phase-flip block-syndrome pattern is injective: the pair of outer readings identifies the block.
★ Bit-flip syndrome, same block: an X error at position j of
block s makes the errored state an eigenstate of block s's stabiliser
pair with the 3-qubit sign pattern xSyndromeSign j.
Bit flips are invisible to the outer stabilisers: X commutes with
X^{⊗6}, so both outer readings stay +1.
★ Phase-flip syndrome, degenerate: a Z error at any inner
position j of block s makes the errored state an eigenstate of the
outer pair with the block pattern zSyndromeSign s — the reading depends
only on the block, never on j.
Phase flips are invisible to every inner stabiliser: Z's commute,
so all six inner readings stay +1.
Corrections: the headline theorems #
★★ Bit-flip correction at every position: re-applying the
syndrome-identified X restores the Shor logical state exactly.
The recovery core: Z₁·Z_j placed in any slot fixes the logical
state — the block degeneracy, lifted.
★★ Degenerate phase-flip correction: applying Z to the first
qubit of the syndrome-identified block restores the state whichever
inner qubit was hit — the outer syndrome cannot see j, and thanks to the
code's degeneracy the recovery does not need to.
★★ Composite (XZ, i.e. Y up to phase) correction: the two
recoveries compose — apply the identified X, then the block's Z₁. With
pauli_decomposition this completes the discretised single-error set
{I, X, Z, XZ} at every one of the nine positions.