Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

§6, p. 1504 — the discrete-log circuit gives a good output with probability at least 1/4801/4801/480

Proved
ShorAlgorithms.DiscreteLog.good_output_prob_ge

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

discrete-logarithmp2o-batch-p200bp2o-gran-per-chapterp2o-plan-paperp2o-v1quantum-algorithms

Throughout, ppp is a prime, ggg is a generator of the multiplicative group (Z/pZ)×(\mathbb Z/p\mathbb Z)^\times(Z/pZ)× (an element of order p−1p-1p−1), rrr is an integer with 0≤r<p−10\le r<p-10≤r<p−1 and x=grx=g^rx=gr (so rrr is the discrete logarithm of xxx), and q=2lq=2^lq=2l is a power of 222 with p<q<2pp<q<2pp<q<2p.

Run Shor's discrete-logarithm circuit: prepare the state

1p−1∑a=0p−2∑b=0p−2∣a,b,gax−b (mod p)⟩,\frac{1}{p-1}\sum_{a=0}^{p-2}\sum_{b=0}^{p-2}|a,b,g^ax^{-b}\ (\mathrm{mod}\ p)\rangle,p−11​a=0∑p−2​b=0∑p−2​∣a,b,gax−b (mod p)⟩,

apply the Fourier transform AqA_qAq​ (entries q−1/2e2πiac/qq^{-1/2}e^{2\pi i ac/q}q−1/2e2πiac/q) to each of the first two registers, and measure all three registers, obtaining ∣c,d,y⟩|c,d,y\rangle∣c,d,y⟩. The output is good if (c,d)(c,d)(c,d) satisfies (6.10) ∣{T}q∣≤12|\{T\}_q|\le\frac12∣{T}q​∣≤21​ with T=rc+d−rp−1{c(p−1)}qT=rc+d-\frac{r}{p-1}\{c(p-1)\}_qT=rc+d−p−1r​{c(p−1)}q​, and (6.11) ∣{c(p−1)}q∣≤q/12|\{c(p-1)\}_q|\le q/12∣{c(p−1)}q​∣≤q/12. Then

Pr⁡[the observed output is good] ≥ 1480.\Pr[\text{the observed output is good}]\ \ge\ \frac{1}{480}.Pr[the observed output is good] ≥ 4801​.

This constant success probability is what makes the quantum discrete-logarithm algorithm run in expected polynomial time: from a few good outputs the discrete logarithm rrr can be deduced.

Formalization Note The paper states the intermediate bound "at least p/(240q)p/(240q)p/(240q)"; its own count gives (p−1)/(240q)(p-1)/(240q)(p−1)/(240q), which still yields 1/4801/4801/480 because qqq and 2p2p2p are both even, so q<2pq<2pq<2p forces q≤2(p−1)q\le2(p-1)q≤2(p−1). Only 1/4801/4801/480 is stated. The state preparation by testing and restarting is not formalized; the state (6.1) is taken as given.

Preamble
import Mathlib
import Definitions.Def_ShorAlgorithms_DiscreteLog_outcomeProb
import Definitions.Def_ShorAlgorithms_DiscreteLog_IsGood
Formal statement
namespace ShorAlgorithms.DiscreteLog

open Classical in
/-- Shor (1997), §6, p. 1504 ("the probability of observing some good state is … at least
1/480"): for every prime `p`, generator `g` of `(ℤ/p)ˣ`, discrete logarithm `r` with
`0 ≤ r < p - 1` (`x = g^r`), and `q = 2^l` with `p < q < 2p`, the probability that the observed
state `|c, d, y⟩` of the discrete-logarithm circuit is good ((6.10) and (6.11)) is at least
`1/480`. -/
theorem good_output_prob_ge (p : ℕ) [hp : Fact p.Prime] (g : (ZMod p)ˣ) (hg : orderOf g = p - 1)
    (r : ℕ) (hr : r < p - 1) (q l : ℕ) (hq : q = 2 ^ l) (hpq : p < q) (hqp : q < 2 * p) :
    (1 : ℝ) / 480 ≤ ∑ c : Fin q, ∑ d : Fin q,
      if IsGood p q r c d then ∑ y : (ZMod p)ˣ, outcomeProb p g (g ^ r) q c d y else 0 := by sorry

end ShorAlgorithms.DiscreteLog
Source
Shor, Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer, SIAM J. Comput. 26(5) (1997), p. 1504, §6 ("… the probability of observing some good state is at least p/(240q)p/(240q)p/(240q), or at least 1/4801/4801/480 (since q<2pq < 2pq<2p).")
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