A formal proof of the Ramanujan--Nagell theorem in Lean 4
Pith reviewed 2026-05-10 16:09 UTC · model grok-4.3
The pith
A complete Lean 4 formalization establishes that x squared plus 7 equals 2 to the n only for the five listed solution pairs.
A machine-rendered reading of the paper's core claim, the machinery that carries it, and where it could break.
Core claim
The paper presents a complete formalization in Lean 4 with Mathlib of the Ramanujan-Nagell theorem stating that the only integer solutions to x squared plus 7 equals 2 to the n are the pairs (n, x) in the set with n equals 3 and x plus or minus 1, n equals 4 and x plus or minus 3, n equals 5 and x plus or minus 5, n equals 7 and x plus or minus 11, and n equals 15 and x plus or minus 181. The formalization covers the full proof strategy together with all supporting algebraic number theory facts about the field Q of square root of negative 7.
What carries the argument
The Lean 4 formalization of the ring of integers, class number, and unit group of the quadratic field Q of square root of negative 7, which carries the descent and bounding arguments that restrict the possible exponents n.
If this is right
- The listed solution pairs are now available as a verified lemma inside Lean for direct reuse in other formal proofs.
- The supporting infrastructure for quadratic fields, rings of integers, class numbers, and unit groups becomes part of the permanent Mathlib library.
- Textbook proofs that rely on similar algebraic number theory can be translated into machine-checked form using the same techniques.
- The documented challenges show precisely where informal proofs must be expanded to meet the requirements of interactive theorem provers.
Where Pith is reading between the lines
- The same formalization approach could be applied to other exponential Diophantine equations whose proofs use class-group computations.
- Once the quadratic-field tools exist, they lower the barrier for formalizing further results that depend on unique factorization in quadratic rings.
- The explicit recording of every definition and lemma makes it possible to extract a human-readable outline of the proof that matches the original textbook steps.
Load-bearing premise
The Lean code correctly encodes the textbook definitions and proof steps for the quadratic field and the Diophantine argument without introducing or omitting any logical content.
What would settle it
An explicit integer pair (n, x) satisfying x squared plus 7 equals 2 to the n that lies outside the five listed pairs, or a detected error in the Lean code that severs the chain of verified implications from the field properties to the solution list.
Figures
read the original abstract
We present a complete formalization, in the Lean interactive theorem prover with the Mathlib library, of the Ramanujan--Nagell theorem: the only integer solutions to the Diophantine equation $x^2 + 7 = 2^n$ are $(n,x) \in \{(3,\pm1),(4,\pm3),(5,\pm5),(7,\pm11),(15,\pm181)\}$. The formalization includes all dependencies, notably the computation of the ring of integers of the quadratic field $\mathbb{Q}(\sqrt{-7})$, its class number, and unit group. We describe the proof strategy, the architecture of the formalization, and the challenges encountered in bridging the gap between textbook proofs and their machine-checked counterparts, with particular attention to the algebraic number theory infrastructure required.
Editorial analysis
A structured set of objections, weighed in public.
Referee Report
Summary. The manuscript presents a complete formalization in Lean 4 (with Mathlib) of the Ramanujan-Nagell theorem: the only integer solutions to the equation x² + 7 = 2ⁿ are the pairs (n, x) ∈ {(3, ±1), (4, ±3), (5, ±5), (7, ±11), (15, ±181)}. The formalization includes the full algebraic-number-theoretic infrastructure (ring of integers of ℚ(√-7), its class number, and unit group) together with the Diophantine argument, and describes the proof strategy, architecture, and encoding challenges.
Significance. If the encoding is faithful, the result is significant because it supplies a machine-checked proof that reduces directly to the axioms of Lean and Mathlib with no free parameters, fitted data, or circular definitions. The work also contributes reusable formalizations of quadratic-field primitives that have already appeared in other Mathlib developments, thereby lowering the barrier for future formalizations of similar Diophantine results.
minor comments (1)
- The description of the proof architecture would benefit from an explicit listing of the main Lean files or modules and their dependencies, so that readers can locate the formalization of the class-number computation and the descent step without searching the repository.
Simulated Author's Rebuttal
We thank the referee for their positive assessment of our manuscript and for recommending acceptance. We are pleased that the contribution of the complete Lean 4 formalization of the Ramanujan--Nagell theorem, including the supporting algebraic number theory infrastructure, is recognized as significant.
Circularity Check
No circularity: deductive formalization to Lean/Mathlib axioms
full rationale
The paper delivers a complete Lean 4 formalization of the Ramanujan-Nagell theorem, encoding the full Diophantine argument together with explicit computations of the ring of integers of Q(√-7), its class number, and unit group. All steps reduce directly to the axioms and definitions in Mathlib (already used in other quadratic-field formalizations) with no fitted parameters, self-referential definitions, predictions that loop back to input data, or load-bearing self-citations. The central claim holds by construction once the code type-checks, making the derivation self-contained against external benchmarks.
Axiom & Free-Parameter Ledger
axioms (2)
- standard math Axioms of mathematics as encoded in Lean 4
- domain assumption Correctness of Mathlib implementations for quadratic fields, class numbers, and unit groups
discussion (0)
Sign in with ORCID, Apple, or X to comment. Anyone can read and Pith papers without signing in.