Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Continued fractions recover j/gcd⁡(j,r)j/\gcd(j,r)j/gcd(j,r) and r/gcd⁡(j,r)r/\gcd(j,r)r/gcd(j,r) from an approximation within 1/(2r2)1/(2r^2)1/(2r2)

Proved
ShorWiki.continued_fraction_recovers

by Lucas · Oct 13, 2026 · Mathlib 0df444a (Lean v4.33.1)

quantum-computingshor-algorithm

Let j≥0j \ge 0j≥0 and r≥1r \ge 1r≥1 be integers and let φ\varphiφ be a real number with

∣jr−φ∣<12r2.\left|\frac{j}{r} - \varphi\right| < \frac{1}{2r^2}.​rj​−φ​<2r21​.

Then some convergent of the continued fraction expansion of φ\varphiφ equals

j/gcd⁡(j,r)r/gcd⁡(j,r)\frac{j/\gcd(j,r)}{r/\gcd(j,r)}r/gcd(j,r)j/gcd(j,r)​

in lowest terms; that is, the continued fractions algorithm run on φ\varphiφ recovers both j/gcd⁡(j,r)j/\gcd(j,r)j/gcd(j,r) and r/gcd⁡(j,r)r/\gcd(j,r)r/gcd(j,r).

This is the classical post-processing step that turns the measured approximation of a phase j/rj/rj/r into the reduced fraction itself.

Formalization Note The article states the hypothesis with ≤\le≤; it is formalized with strict <<<. With ≤\le≤ the statement fails for the standard continued fraction expansion used by Mathlib's Real.convergent: for j=r=1j = r = 1j=r=1 and φ=1/2\varphi = 1/2φ=1/2 one has ∣1−1/2∣=1/(2⋅12)|1 - 1/2| = 1/(2\cdot 1^2)∣1−1/2∣=1/(2⋅12), but the convergents of 1/21/21/2 are 000 and 1/21/21/2, never 111. In the application the inequality is strict (milestone register size bound and r<Nr < Nr<N). The article's hypothesis "jjj and rrr are nnn-bit integers" places no restriction and is omitted.

Preamble
import Mathlib
import Definitions.Def_ShorWiki_Defs

open Matrix Kronecker
Formal statement
namespace ShorWiki

theorem continued_fraction_recovers (j r : ℕ) (hr : 0 < r) (φ : ℝ)
    (h : |(j : ℝ) / r - φ| < 1 / (2 * (r : ℝ) ^ 2)) :
    ∃ m : ℕ, (Real.convergent φ m).num = ((j / Nat.gcd j r : ℕ) : ℤ) ∧
      (Real.convergent φ m).den = r / Nat.gcd j r := by sorry

end ShorWiki
Source
Wikipedia, "Shor's algorithm", revision oldid=1378862216, https://en.wikipedia.org/w/index.php?title=Shor%27s_algorithm&oldid=1378862216, section "Choosing the size of the first register", Theorem (PDF p. 6)
Human review
  • Endorsed by Shuze Chen · Oct 13, 2026

    Confirmed by the moderator at approval.

  • Endorsed by Lucas · Oct 13, 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