Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Quantum order finding recovers the order rrr with probability at least φ(r)/3r\varphi(r)/3rφ(r)/3r

Proved
ShorAlgorithms.OrderFinding.order_recovered_prob_ge

by mikedeng1 · Sep 29, 2026 · Mathlib 0df444a (Lean v4.33.1)

order-findingp2o-batch-p200bp2o-gran-per-chapterp2o-plan-paperp2o-v1probabilityquantum-algorithms

There is a threshold NNN such that the following holds for every n≥Nn \ge Nn≥N. Let xxx be coprime to nnn and let rrr be its multiplicative order modulo nnn, the least r≥1r \ge 1r≥1 with xr≡1(modn)x^r \equiv 1 \pmod nxr≡1(modn). Let q=2lq = 2^lq=2l be the power of 222 with n2≤q<2n2n^2 \le q < 2n^2n2≤q<2n2. Run Shor's order-finding procedure: prepare the state

1q1/2∑a=0q−1∣a⟩∣xa mod n⟩,\frac{1}{q^{1/2}}\sum_{a=0}^{q-1}|a\rangle|x^a \bmod n\rangle,q1/21​a=0∑q−1​∣a⟩∣xamodn⟩,

apply the Fourier transform AqA_qAq​ to the first register, measure, and round c/qc/qc/q to the nearest fraction with denominator smaller than nnn. Then the probability that the observed ccc gives us rrr (the rounded fraction has denominator rrr in lowest terms) is at least

φ(r)3r.\frac{\varphi(r)}{3r}.3rφ(r)​.

This is the paper's main claim about the quantum part of the factoring algorithm; combined with φ(r)/r>δ/log⁡log⁡r\varphi(r)/r > \delta/\log\log rφ(r)/r>δ/loglogr, it shows that O(log⁡log⁡r)O(\log\log r)O(loglogr) repetitions find rrr with high probability.

Formalization Note The probability of the event is ∑c good∑y∈Z/n∣Ψ(c,y)∣2\sum_{c \text{ good}} \sum_{y \in \mathbb{Z}/n} |\Psi(c, y)|^2∑c good​∑y∈Z/n​∣Ψ(c,y)∣2, where Ψ\PsiΨ is built by applying AqA_qAq​ to the first register of (5.2); summing over all yyy is exact, since values yyy that are not powers of xxx have probability 000. "Gives us rrr" is yieldsOrder. The threshold NNN comes first and is uniform in xxx and qqq; it is inherited from the paper's per-state bound, which holds "for sufficiently large nnn". [NeZero n] makes Z/n\mathbb{Z}/nZ/n finite.

Preamble
import Mathlib
import Definitions.Def_ShorAlgorithms_OrderFinding_outcomeProb
import Definitions.Def_ShorAlgorithms_OrderFinding_yieldsOrder
Formal statement
namespace ShorAlgorithms.OrderFinding

open Classical in
/-- Shor (1997), §5, p. 1501 (goal). For all sufficiently large `n` (threshold `N` uniform in
`x` and `q`): let `x` be coprime to `n` with order `r`, and `q = 2^l` with `n² ≤ q < 2n²`.
Run the order-finding algorithm (state (5.2), Fourier transform `A_q` on the first register,
measurement). The probability that the observed `c` gives us `r` by rounding `c/q` to the
nearest fraction with denominator smaller than `n` is at least `φ(r)/(3r)`. -/
theorem order_recovered_prob_ge : ∃ N : ℕ, ∀ (n : ℕ) [NeZero n], N ≤ n →
    ∀ x : ℕ, Nat.Coprime x n → ∀ q l : ℕ, q = 2 ^ l → n ^ 2 ≤ q → q < 2 * n ^ 2 →
    (Nat.totient (orderOf (x : ZMod n)) : ℝ) / (3 * (orderOf (x : ZMod n) : ℝ)) ≤
      ∑ c ∈ (Finset.univ : Finset (Fin q)).filter
          (fun c : Fin q => yieldsOrder n q (orderOf (x : ZMod n)) (c : ℕ)),
        ∑ y : ZMod n, outcomeProb n x q c y := by sorry

end ShorAlgorithms.OrderFinding
Source
Shor, Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer, SIAM J. Comput. 26(5) (1997), p. 1501, §5, "Since each of these states occurs with probability at least 1/3r^2, we obtain r with probability at least φ(r)/3r"; setup pp. 1498–1500
Human review
  • Endorsed by Shuze Chen · Oct 1, 2026

    Confirmed by the moderator at approval.

  • Endorsed by mikedeng1 · Oct 1, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me