A formal proof of the Ramanujan--Nagell theorem in Lean 4
The Ramanujan-Nagell theorem (the only integer solutions to x^2 + 7 = 2^n) had no machine-checked formal proof. Formalizing it requires substantial algebraic number theory infrastructure including rings of integers, class numbers, and unit groups of quadratic fields.
The formalization in Lean 4 with Mathlib proves that Q(sqrt(-7)) is norm-Euclidean (rather than using class number one) to obtain unique factorization directly from the Euclidean algorithm, which is considerably easier to formalize. The development includes the ring of integers Z[(1+sqrt(-7))/2], its norm function, norm-Euclidean property, and unit group computation.
A complete machine-checked proof of the Ramanujan-Nagell theorem: the only integer solutions to x^2 + 7 = 2^n are (n,x) in {(3,+/-1),(4,+/-3),(5,+/-5),(7,+/-11),(15,+/-181)}. The formalization comprises two files built directly on Mathlib, with an interactive dependency graph and proof blueprint publicly available.
