Shor's algorithm — period recovery (S5, uniqueness route) #
Category: 3-Local (QM-validity), pure finite number theory.
Tranche S5 of specs/shor-plan.md. After phase estimation (S4) a single run yields a count c
with |c/T - s/r| ≤ 1/(2T) for the true order r (s/r in lowest terms). This file proves the
recovery-correctness content: that bound, together with r·r' < T, pins down s/r
uniquely among lowest-terms fractions, so the order r is determined by the measurement.
The argument is the elementary "distinct fractions are far apart" estimate
(abs_sub_rat_ge: distinct a/b, c/d differ by at least 1/(b·d)), not the continued-fraction
machinery. Mathlib has the forward CF bound (abs_sub_convergents_le') but not the Legendre
converse; this route sidesteps it.
Honest scope. This is the information-theoretic determination of r (why recovery is
possible: the measurement has a unique consistent answer). It is NOT the constructive
continued-fraction computation of r from c/T; the constructive Legendre-on-GenContFract
extraction is a heavier, separately-scoped alternative, deferred.
Composition with S4 (QuantumInfo.phase_estimation_lower_bound,
Mathlib/QuantumInfo/PhaseEstimation.lean since 2026-08-29, with the Shor corollary
shor_phase_estimation_lower_bound in ShorCore.lean): S4 gives prob ≥ 4/π² for the
closest-integer outcome, i.e. the event |c/T - s/r| ≤ 1/(2T); S5 shows that on that event r is
determined. For Shor with T ≥ N² > r² (so r, r' < √T and r·r' < T with slack) a single run
determines r with probability ≥ 4/π².
Tranche S6 (nontrivial_factor) adds the classical reduction "order-finding implies
factoring": for an even order r of a unit a with a^(r/2) ≢ ±1 (mod N), the element
x = a^(r/2) is a nontrivial square root of unity (N ∣ x²-1, N ∤ x±1), and
gcd(x-1, N) is then a proper nontrivial divisor of N. This is the step that turns the
quantum period output into an actual factor.
Uniqueness of a close fraction: if a/b and c/d (positive denominators with
b·d < T) are both within 1/(2T) of the same rational x, they are equal.
Shor period determination (headline): the measured count c determines the order r.
Given the true s/r and any candidate s'/r', both in lowest terms with r·r' < T and both
within 1/(2T) of c/T, the two coincide: s = s' and r = r'. So the order r is the unique
denominator consistent with the measurement.
S6 — factoring from a nontrivial square root of unity (the classical Shor step).
If x is a nontrivial square root of 1 modulo N (so N ∣ x²-1 but N ∤ x-1 and
N ∤ x+1), then g := gcd(x-1, N) is a proper nontrivial divisor of N:
1 < g, g < N, and g ∣ N. Here Int.gcd : ℤ → ℤ → ℕ, so all three conjuncts are
statements about the natural number g. This is the reduction that converts the quantum
order-finding output into an actual factor of N.
Bridge from an even-order unit to S6's nontrivial-square-root hypotheses.
For a unit a of (ZMod N)ˣ of even order r = orderOf a with a^(r/2) ≢ ±1 (mod N),
the integer x lifting y := a^(r/2) satisfies the three hypotheses of nontrivial_factor:
N ∣ x²-1, N ∤ x-1, N ∤ x+1. The square-root content is y² = 1 (since
(r/2)·2 = r and a^r = 1).
Even order ⟹ factor (the full classical reduction order-finding ⟹ factoring).
Composes even_order_sqrt_unity with nontrivial_factor: for an even order r of a unit a
with a^(r/2) ≢ ±1 (mod N), the natural number gcd(a^(r/2)-1, N) (via the integer lift x)
is a proper nontrivial divisor of N.