Shor's algorithm — quantum core (M1 + M1.5: S1 + S2 + S3, ideal case r ∣ T) #
Category: 3-Local (QM-validity).
Milestone M1 of specs/shor-plan.md: the quantum heart of Shor's order-finding algorithm,
the part that needs no number-theory tail. Three pieces, all finite-dimensional QM:
S1 — the multiply-by-
aoracle. On the genuine work registerEuclideanSpace ℂ (ZMod N), the modular-exponentiation oracle is the permutation|y⟩ ↦ |a·y⟩induced by a unita : (ZMod N)ˣ(mulOracle,mulOracle_basisState). A genuine permutation unitary, not a toy cyclic shift onFin r.S2 — eigenstructure of multiply-by-
a. Withr = orderOf aandω = exp(2πi/r), the statesu_s = (1/√r) ∑_{j<r} conj(ω)^{s j} |a^j⟩are eigenvectors with eigenvalueω^s = e^{2πi s/r}(mulOracle_eigU), supported on the orbit{a^j}, and they reassemble|1⟩ = (1/√r) ∑_{s<r} u_s(sum_eigU). This is the hinge turning order-finding into phase estimation: the eigenphases are exactly the multiples of1/r.S3 — phase-estimation exactness. On the counting register
EuclideanSpace ℂ (Fin T), the inverse QFT inverts the QFT exactly (applyQFTinv_phaseColumn), so the phase state carrying eigenvalueω_T^{j₀}is read out as|j₀⟩with certainty (phase_estimation_exact). (Relocated 2026-08-29: S3's generic core and S4's4/π²bound are Cat-1 —Mathlib/QuantumInfo/PhaseEstimation.lean— and this file consumes them; the register primitives were folded into the generalisedMathlib/QuantumInfo/Register.lean.)Bridge S2↔S3. In the ideal case
r ∣ T, the eigenphaseω_r^s = ω_T^{s·(T/r)}(qftω_div), so the counting-register phase state carrying eigenvalueω_r^sis exactly the QFT columns·(T/r). Inverse-QFT then reads the order's phase off a single eigenvalue branch with certainty:prob = 1at indexs·(T/r)(shor_order_readout, the M1 headline).
M1.5 — the joint two-register state and the full ideal-case output distribution #
M1.5 assembles the genuine two-register joint state on EuclideanSpace ℂ (Fin T × ZMod N) and
proves the full ideal-case (r ∣ T) order-finding measurement distribution:
- Joint register.
tensorCN φ ψ(coordinateφ c * ψ y) and the counting-register inverse QFTqftInvCount(acting on theFin Tindex only), with the key reductionqftInvCount_tensorCN : qftInvCount (tensorCN φ ψ) = tensorCN (applyQFTinv T φ) ψ. The genuine Born marginal on the counting register isprobCount Φ c = ∑_y ‖Φ (c, y)‖². - The faithful state.
jointModexp ais the modular-exponentiation oracle|x⟩|y⟩ ↦ |x⟩|a^x·y⟩(a genuine permutation), andjointModexp_initialproves it sends the prepareduniformCount ⊗ |1⟩topostModexpState = (1/√T) ∑_x |x⟩|a^x⟩. SopostModexpStateIS the modexp output, not a posited form. - Eigenbasis expansion.
basisState_apow_eq(roots-of-unity inversion, dual tosum_eigU) rewrites|a^x⟩in theeigUeigenbasis;postModexp_eq_eigenbasisthen expands the joint state as(1/√r) ∑_s (phase column s·T/r) ⊗ u_s, andqftInvCount_postModexpapplies the inverse QFT to read each branch as|s·T/r⟩ ⊗ u_s. - HEADLINE
shor_order_distribution: forr ∣ T, measuring the counting register givesprobCount = 1/ron eachs·(T/r)(s < r), viaeigU_norm(‖u_s‖ = 1) and the index injectivitybridgeIndex_inj;shor_order_distribution_zerogives0off thermultiples. This is the uniform-1/rmarginal M1 flagged as deferred.
Honest scope #
M1 + M1.5 deliver the genuine oracle (S1), its eigenstructure with eigenvalues e^{2πi s/r} and
the |1⟩ = (1/√r) ∑_s |u_s⟩ decomposition (S2), and the full ideal-case (r ∣ T) order-finding
output distribution (S3): on the genuine two-register modexp state, the counting-register
measurement is uniform 1/r on the r multiples {s·T/r : s < r} and 0 elsewhere.
(Status corrected 2026-08-29 — this paragraph had listed S4–S7 as remaining, which predated
their landing:) S4 (the 4/π² bound, now Cat-1 in PhaseEstimation.lean with the Shor
corollary below), S5 (ShorRecovery.lean), S6 (ShorCapstone.lean) and S7b (ShorRandomA.lean)
are landed. What remains for full Shor: the two-register r ∤ T measurement marginal
(cross-term control across the r eigen-branches; see the S4 section note below). All per
specs/shor-plan.md.
Register primitives #
The computational-basis primitives basisState/prob and the coordinate bridge sum_coord
are the general finite-index R1 API (Mathlib/QuantumInfo/Register.lean, generalised
2026-08-29 — this file previously carried a verbatim general-index copy mirroring the then
bitstring-only R1). Shor's registers are the instances ι = ZMod N (work) and ι = Fin T
(counting).
S1 — the multiply-by-a oracle on EuclideanSpace ℂ (ZMod N) #
The multiply-by-a oracle |y⟩ ↦ |a·y⟩: the permutation operator reindexing a register
state by multiplication by the unit a. The coordinate at y is pulled back from a⁻¹·y, so a
basis state |y⟩ maps to |a·y⟩.
Equations
- CSD.Empirical.QM.Shor.mulOracle a ψ = (WithLp.equiv 2 (ZMod N → ℂ)).symm fun (y : ZMod N) => ψ.ofLp (↑a⁻¹ * y)
Instances For
S1 key fact: the oracle sends the basis state |y⟩ to |a·y⟩.
S2 — eigenstructure of the multiply-by-a oracle #
The eigenvector u_s = (1/√r) ∑_{j<r} conj(ω)^{s j} |a^j⟩, supported on the orbit.
Equations
- One or more equations did not get rendered due to their size.
Instances For
S2 eigenvector lemma: mulOracle a (u_s) = ω^s · u_s, with ω = exp(2πi/r). The oracle
shifts the orbit index by one; reindexing by the cyclic shift and using conj ω = ω⁻¹,
ω^r = 1, each summand picks up the common phase ω^s.
S2 decomposition lemma: (1/√r) ∑_{s<r} u_s = |1⟩. Summing the eigenvectors collapses the
phase sum by roots-of-unity orthogonality to the single orbit term |a^0⟩ = |1⟩.
S3 — phase estimation on the counting register EuclideanSpace ℂ (Fin T) #
The S3 core — applyQFT/applyQFTinv, phaseColumn, applyQFTinv_phaseColumn,
phase_estimation_exact — is the generic phase-estimation API and lives in
Mathlib/QuantumInfo/PhaseEstimation.lean (Cat-1; relocated 2026-08-29). This file keeps the
Shor-specific bridge below.
Bridge S2 ↔ S3 — the eigenphase reads out the order #
In the ideal case r ∣ T the eigenphase ω_r^s of mulOracle a is a T-th root: precisely
ω_T^{s·(T/r)}. So the counting-register phase state carrying eigenvalue ω_r^s is the QFT
column s·(T/r), and inverse-QFT reads the order's phase off it with certainty.
ω_r = ω_T^{T/r} when r ∣ T (r, T > 0): both equal exp(2πi/r).
Bridge: the counting-register phase state carrying eigenvalue ω_r^s is exactly the QFT
column s·(T/r).
M1 headline (shor_order_readout): in the ideal case r ∣ T, inverse-QFT of the
counting-register phase state carrying eigenvalue ω_r^s yields the basis state s·(T/r) with
certainty. This is phase estimation reading the order's phase s/r exactly.
M1.5 — the joint two-register state and the ideal-case output distribution #
The product-index joint register EuclideanSpace ℂ (Fin T × ZMod N), the modular-exponentiation
oracle |x⟩|y⟩ ↦ |x⟩|a^x·y⟩, and the full ideal-case (r ∣ T) measurement distribution.
The joint register EuclideanSpace ℂ (Fin T × ZMod N) #
Rebuilt 2026-08-29 (plan specs/amplitude-amplification-plan.md, AA-5b step 1): the joint
register machinery is now the Fin T × ZMod N instance of the generic
Mathlib/QuantumInfo/JointRegister.lean (tensorState/matrixLeft/probLeft) — the local
names and statements are unchanged, the proofs delegate. The r ∤ T marginal this file defers
additionally gains the general orthogonal-branch mixture law
probLeft_sum_tensor_orthogonal to consume when it is attempted.
The tensor product of a counting-register state and a work-register state:
the tensorState instance at ι₁ = Fin T, ι₂ = ZMod N.
Equations
Instances For
The tensor commutes with finite sums in the counting factor (tensorState_sum_left).
The tensor commutes with finite sums in the work factor (tensorState_sum_right).
On basis states the tensor is the joint basis state: |c⟩ ⊗ |y⟩ = |(c, y)⟩
(tensorState_basis).
The inverse QFT on the counting register only: the matrixLeft (qftMatrix T)ᴴ
instance, coordinate (qftInvCount Φ) (c, y) = ∑_x (qftMatrix T)ᴴ c x · Φ (x, y).
Equations
Instances For
The partial inverse QFT is linear (matrixLeft_smul).
The partial inverse QFT commutes with finite sums (matrixLeft_sum).
Key reduction: the partial inverse QFT commutes with the tensor and reduces to M1's
applyQFTinv on the counting factor (matrixLeft_tensorState).
The faithful modular-exponentiation state #
The modular-exponentiation oracle |x⟩|y⟩ ↦ |x⟩|a^x·y⟩ on the joint register, the
genuine permutation reindexing the work register by multiplication by a^x.
Equations
Instances For
The uniform counting register (1/√T) ∑_x |x⟩.
Equations
- CSD.Empirical.QM.Shor.uniformCount T = (↑√↑T)⁻¹ • ∑ x : Fin T, QuantumInfo.basisState x
Instances For
The prepared initial state uniformCount ⊗ |1⟩.
Equations
Instances For
The post-modexp state (1/√T) ∑_x |x⟩|a^x⟩: the genuine output of the oracle on the
prepared input.
Equations
Instances For
Faithfulness link: the oracle on the prepared input uniformCount ⊗ |1⟩ produces exactly
postModexpState = (1/√T) ∑_x |x⟩|a^x⟩.
Two eigenstructure facts #
The orbit map j ↦ a^j is injective on Fin (ord a) (distinct powers below the order).
The eigenbasis expansion of the post-modexp state #
The eigenphase counting state (1/√T) ∑_x ω_r^{s x} |x⟩ equals the QFT column s·(T/r),
re-stated with the M1 omega a = qftω r notation.
Apply inverse-QFT and read the distribution #
Inverse-QFT of the post-modexp state: qftInvCount postModexpState = (1/√r) ∑_s |s·T/r⟩ ⊗ u_s. The partial inverse QFT reduces each phase column to a basis state.
HEADLINE — the ideal-case order-finding distribution. For r ∣ T, measuring the counting
register of the inverse-QFT'd modexp state gives prob = 1/r on each multiple s·(T/r). This is
the uniform-1/r spread over the order's multiples that order recovery uses.
Complement: off the r multiples {s·(T/r)}, the counting-register probability is 0.
S4 — the Shor corollary of the 4/π² phase-estimation bound #
The S4 analytic core — phaseStateR, the Dirichlet amplitude (applyQFTinv_phaseStateR_apply),
the closed-form probability (prob_phaseStateR_eq) and the 4/π² lower bound
(phase_estimation_lower_bound, Jordan inequality against |sin t| ≤ |t|) — is generic in T
and lives in Mathlib/QuantumInfo/PhaseEstimation.lean (Cat-1; relocated 2026-08-29, no
statement changed). What is Shor's is the instantiation φ = s/r below.
Honest scope (unchanged). S4 is the single-eigenvector lower bound on a fixed real phase φ
(the general-r analogue of M1's eigenPhase_eq_phaseColumn, which only identified the counting
state with an exact QFT column in the divisible case r ∣ T). The full two-register r ∤ T
measurement marginal — controlling the cross-terms across the r eigen-branches u_s to get the
per-outcome probability of the joint state — is beyond S4 and not done here.
S4d — the Shor corollary. Instantiating φ = s/r, the s-branch counting state's inverse-QFT
readout at the closest index c to s·T/r has probability ≥ 4/π². This is the general-r
(r ∤ T) analogue of the M1 exact readout shor_order_readout: in the divisible case the phase
state was an exact QFT column read with certainty; here the order phase s/r is generally not a
multiple of 1/T, and the best one gets is the Dirichlet-kernel constant 4/π² at the nearest
index. The two-register marginal across the r branches is beyond S4 (see the section docstring).
The hr : 0 < r precondition is recorded for the spec reading (r = orderOf a > 0); it is
already implied by s : Fin r, so the proof does not consume it.