Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

§5, eqs. (5.5)–(5.6) — probability of observing ∣c,xk mod n⟩|c, x^k \bmod n\rangle∣c,xkmodn⟩

Proved
ShorAlgorithms.OrderFinding.outcome_prob_eq

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

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

Let n≥1n \ge 1n≥1, let xxx be coprime to nnn with multiplicative order rrr modulo nnn, and let q=2lq = 2^lq=2l be the power of 222 with n2≤q<2n2n^2 \le q < 2n^2n2≤q<2n2. Let 0≤c<q0 \le c < q0≤c<q and 0≤k<r0 \le k < r0≤k<r. The probability that measuring the final state (5.4) of the order-finding algorithm gives ∣c,xk mod n⟩|c, x^k \bmod n\rangle∣c,xkmodn⟩ equals both

∣1q∑0≤a<qxa≡xkexp⁡(2πiac/q)∣2and∣1q∑b=0⌊(q−k−1)/r⌋exp⁡(2πi(br+k)c/q)∣2.\left|\frac{1}{q}\sum_{\substack{0\le a<q\\ x^a\equiv x^k}}\exp(2\pi i a c/q)\right|^2 \quad\text{and}\quad \left|\frac{1}{q}\sum_{b=0}^{\lfloor(q-k-1)/r\rfloor}\exp\bigl(2\pi i(br+k)c/q\bigr)\right|^2 .​q1​0≤a<qxa≡xk​∑​exp(2πiac/q)​2and​q1​b=0∑⌊(q−k−1)/r⌋​exp(2πi(br+k)c/q)​2.

The first expression collects the paths ∣a⟩↦∣c⟩|a\rangle \mapsto |c\rangle∣a⟩↦∣c⟩ that end in the same second-register value; the second rewrites the index set {a:a≡k(modr)}\{a : a \equiv k \pmod r\}{a:a≡k(modr)} as a=br+ka = br + ka=br+k. The second form is the starting point of the estimate (5.11).

Formalization Note The probability is outcomeProb, the squared modulus of the amplitude of the state built by applying AqA_qAq​ to (5.2). ⌊(q−k−1)/r⌋\lfloor (q-k-1)/r \rfloor⌊(q−k−1)/r⌋ is natural-number division, and the natural-number subtraction q−k−1q - k - 1q−k−1 is exact because k<r<n≤qk < r < n \le qk<r<n≤q (the order of a unit is at most φ(n)<n\varphi(n) < nφ(n)<n). The hypotheses on qqq are the section's standing choice of qqq.

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

/-- Shor (1997), §5, eqs. (5.5)–(5.6), p. 1499. Let `r` be the order of `x` mod `n`, let
`q = 2^l` with `n² ≤ q < 2n²`, and let `0 ≤ k < r`. The probability of observing
`|c, x^k (mod n)⟩` in the final state (5.4) equals
(5.5) `|(1/q) ∑_{a < q, x^a ≡ x^k} exp(2πiac/q)|²`, and also equals
(5.6) `|(1/q) ∑_{b=0}^{⌊(q-k-1)/r⌋} exp(2πi(br+k)c/q)|²`.
`(q - k - 1) / r` is natural-number (floor) division; `k < r < n ≤ q` keeps the subtraction
exact. -/
theorem outcome_prob_eq (n x q l : ℕ) (hx : Nat.Coprime x n)
    (hq : q = 2 ^ l) (hnq : n ^ 2 ≤ q) (hq2 : q < 2 * n ^ 2)
    (c : Fin q) (k : ℕ) (hk : k < orderOf (x : ZMod n)) :
    outcomeProb n x q c ((x : ZMod n) ^ k) =
        ‖(1 / (q : ℂ)) * ∑ a ∈ (Finset.univ : Finset (Fin q)).filter
            (fun a : Fin q => (x : ZMod n) ^ (a : ℕ) = (x : ZMod n) ^ k),
          Complex.exp (2 * Real.pi * Complex.I * ((a : ℕ) : ℂ) * ((c : ℕ) : ℂ) / (q : ℂ))‖ ^ 2 ∧
    outcomeProb n x q c ((x : ZMod n) ^ k) =
        ‖(1 / (q : ℂ)) * ∑ b ∈ Finset.range ((q - k - 1) / orderOf (x : ZMod n) + 1),
          Complex.exp (2 * Real.pi * Complex.I *
            (((b * orderOf (x : ZMod n) + k : ℕ)) : ℂ) * ((c : ℕ) : ℂ) / (q : ℂ))‖ ^ 2 := 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. 1499, §5, eqs. (5.5)–(5.6); choice of q p. 1498
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