AI

‘Theorem Proving in Lean 4’ Review: The Free Book That Explains What ‘Checked in Lean’ Means

Updated

  • Book Review
  • AI Math
  • Explainer
VibeCodAI — Code, Build, Innovate

Since November 20, “checked in Lean” has been offered as the reason to believe an AI-assisted proof of the Riemann hypothesis. Theorem Proving in Lean 4, the free official guide to the proof assistant, is the best short course in what that phrase does and does not certify. It is also silent on the tools that did most of the checking.

When Levent Alpöge released a 17-million-line Lean library on November 20 claiming a proof of the Riemann hypothesis, mathematicians were not asked to read 17 million lines. They were asked to trust a process. A day later the Lean FRO and the Mathlib Initiative published a joint statement: “We hereby certify that both the statement and the proof of the Riemann Hypothesis are correct.” MIT’s Andrew Sutherland posted a page of verification runs reporting that the headline theorems “depend only on the three standard axioms.” On November 29, Axiom Math published a Lean proof extending the result to totally real and CM number fields, with a different note attached: the proof “is conditional on three published theorems, which enter as axioms.”

Those sentences carry most of the weight in the current argument over AI and mathematics, and most readers cannot parse them. What is a “standard axiom”? How can a library enter a published theorem as an axiom, and why would anyone allow that? Terence Tao’s written testimony to a House science subcommittee on December 1 described the new situation plainly: “the answers flood in first, but the understanding of where these answers came from, how they connect with the rest of the subject, and which promising new directions they open up, is now lagging behind significantly.”

Over the past week, posts on X about Lean proofs have run at roughly 750 to 1,350 a day. Much of that discussion argues about verification without saying what a Lean kernel actually checks. The most direct free answer to that question is a 12-chapter online book written by the people who built the system.

What the book is

Theorem Proving in Lean 4 is by Jeremy Avigad, Leonardo de Moura, Soonho Kong and Sebastian Ullrich, “with contributions from the Lean Community.” De Moura started the Lean project at Microsoft Research in 2013, according to the book’s introduction. The text is free on lean-lang.org, released under the Apache 2.0 licence, and maintained in a public GitHub repository that dates from August 2021. Earlier editions covered Lean 2 and Lean 3. The current edition says it assumes Lean 4.33.0, the same minor release (v4.33.1) on which Sutherland reports that Alpöge’s library compiled.

The 12 chapters run from dependent type theory and “propositions as types” through tactics, inductive types, recursion, structures and type classes, ending with a chapter on axioms and computation. It is a book about the logic and the language, not about doing research mathematics. That distinction matters later in this review.

This review is based on the current web edition. The chapters discussed below are the ones that bear directly on this month’s verification claims.

A theorem is a definition, and the checker sees only that

The idea that makes the rest of the book work comes in Chapter 3. In Lean, a proposition is a type and a proof is a term of that type. Proving a theorem means constructing an object that the type checker accepts. “To the kernel type checker, there is no difference between the two,” the authors write of theorems and definitions (section 3.2).

This explains why a machine check can be trusted at all. The introduction notes that interactive provers like Lean “provide fully elaborated ‘proof objects’ that can be communicated to other systems and checked independently.” In Chapter 8 the authors say that the equation compiler, the machinery that turns readable recursive definitions into primitive terms, “is not part of the trusted code base; its output consists of terms that are checked independently by the kernel.” By the same logic, the large machinery that helps a user find a proof can contain bugs without making an accepted proof wrong. Only the kernel at the bottom has to be right.

That is the design the Riemann verification relied on. Sutherland’s page lists the exported proof being accepted by Lean’s own kernel and by independently written checkers, among them nanoda and con-leche. One run of Lean’s default kernel over the full export took about 48 hours on a single thread. The book does not describe any of this tooling. It does explain why the tooling makes sense: if the proof is a self-contained object, anyone can write a second checker for it.

A correct proof of the wrong statement

The kernel checks that a proof matches a statement. It cannot check that the statement means what a human thinks it means. In a November 12 post on the Xena Project blog, Imperial College’s Kevin Buzzard lists this as the first of four questions to ask about any Lean claim, “particularly if it is AI-generated.” His example is a two-line “Fermat’s Last Theorem” over the natural numbers that is false, because Lean’s natural numbers include zero and a = b = c = 0 is a counterexample. “This does not stop the statement from compiling!” he writes.

The book prepares readers for this more than its dry exercises suggest. Chapter 7 builds the natural numbers from zero and succ, which is exactly the detail Buzzard’s example turns on. The exercises in section 4.6 ask readers to write, as bare propositions, the statements of Goldbach’s conjecture, the weak Goldbach conjecture, the infinitude of Fermat primes and Fermat’s Last Theorem. Statements like these are where Buzzard says the risk lies. Doing those exercises carefully is a small version of the vetting that, according to the Lean FRO and Mathlib Initiative, Mathlib’s RiemannHypothesis definition received from “experts in Lean and number theory.”

The two ways to cheat, and how Lean reports them

Section 3.2 shows the first shortcut. The axiom command lets a user postulate anything, and the authors immediately demonstrate the danger with axiom unsound : False, followed by a “proof” that 1 = 0. An axiom declaration, they write, “may compromise logical consistency.”

Section 3.6 introduces the second, sorry, which “magically produces a proof of anything.” The book presents it as a scaffolding tool for writing long proofs top-down, and warns that “Lean produces severe warnings when files use or import theorems which depend on it.” Chapter 6 adds that warnings “deserve careful attention.” Section 8.5 links the two: “using sorry is equivalent to using a new axiom, and should be avoided.” It then runs #print axioms on a fake proof of False and shows Lean reporting that it depends on sorryAx.

That one command is the most useful thing a non-specialist can take from the book. #print axioms lists every assumption a theorem ultimately rests on. In ordinary use, a hidden sorry or an added axiom shows up in its output. Buzzard’s third question asks whether the code really proves the theorem as stated. His answer is a tool, lake comparator, that checks the proved statement against a trusted copy and confirms that “only the axioms of mathematics are used in the proof.” It is the same audit, automated across a whole repository.

Why “the three standard axioms” always appear

Chapter 12, “Axioms and Computation,” is the part of the book most worth reading this month. Its summary says that on top of the core type theory, Lean’s standard library adds three things: propositional extensionality, a quotient construction that implies function extensionality, and a choice principle that “magically produces ‘data’ from a proposition asserting its existence.” Their names in Lean are propext, Quot.sound and Classical.choice. The book adds that if a result uses Quot.sound, “it will show up in the #print axioms command” (section 12.4).

Those three names are exactly what Sutherland’s audit log reports for the five headline theorems in Alpöge’s library: “propext, Classical.choice, Quot.sound only.” After this chapter the phrase “standard axioms” stops being jargon. It means the theorems use ordinary classical mathematics and nothing else. The chapter also shows how the law of the excluded middle follows from choice via Diaconescu’s theorem, and it is clear about the price. What is given up is computation: definitions built with choice cannot be run as programs, and Lean makes users mark them noncomputable.

The same chapter makes the Axiom Math result easy to read. An independent audit posted on November 30 reports that #print axioms on its seven main theorems returns the three standard axioms plus External.averagedColmez, External.dasguptaKakde and External.dkswDyadicUnits, three published results stated in Lean but not proved there. The auditor notes that one of the three is still an arXiv preprint, and that whether the Lean axioms faithfully transcribe the printed theorems “is a human reading.” By the book’s standard, the right label for the result is a kernel-checked proof conditional on three theorems, not a kernel-checked proof. Axiom’s own README says as much.

Where the book stops

The book’s limits are as instructive as its strengths. It never mentions Mathlib. We searched all 12 chapters and found no reference to it. The Riemann statements verified this month are written in terms of Mathlib’s definitions of the zeta function, Dirichlet characters and L-functions, and Buzzard’s first question cannot be answered without reading them. The book points readers instead to Lean’s core Init and Std libraries. For the mathematics library, readers need the community’s companion text Mathematics in Lean, which says it “is based on” Mathlib.

Nor does it cover the verification layer now at the centre of public claims. There is nothing on exporting proofs, statement comparators, independent kernels, sandboxing untrusted code, or the soundness bugs Buzzard mentions as having been found and fixed in Lean’s kernel. The book explains why the kernel is the part that must be trusted. It does not mention that the kernel has had bugs, or explain how the community now hedges against more. In fairness, it is a language tutorial, not a verification manual. But a reader who stops at Chapter 12 will understand #print axioms without knowing why Sutherland ran the proof through several independent checkers.

There are smaller signs of age. Chapter 12 still says “This is precisely what Lean's virtual machine does,” wording carried over from the Lean 3 edition, which described compiling to bytecode for a virtual machine evaluator. Formal exercise sections appear in only five of the 12 chapters (3, 4, 5, 7 and 8). The authors recommend running every example in an editor as you go, and the book works best that way. Readers without a background in logic or functional programming should not expect to read it straight through.

How to read it now

For an engineer, journalist or mathematician who wants to assess claims like this month’s, a realistic path is shorter than the whole book. Read Chapters 1 to 4 for propositions as types, quantifiers and equality, and do at least the statement-writing exercises in section 4.6. Read section 6.1 on messages and warnings. Read the end of section 8.5, where #print axioms catches a fake proof. Then read all of Chapter 12. That is a few evenings of work. After it, Buzzard’s four questions and Sutherland’s verification table become documents you can check yourself rather than take on authority.

Then move to Mathematics in Lean for Mathlib. For the specific Riemann results, see our fact-check of what the Lean verification covered, and our earlier piece on the Aaronson–Ambainis Lean proof.

Verdict

Theorem Proving in Lean 4 was not written for a moment in which AI systems produce proofs faster than people can read them. It still turns out to be the right primer for one. It explains why a proof can be checked by a program much smaller than the one that produced it, where the trusted boundary sits, and how every assumption a result depends on can be listed with one command. What it leaves out, Mathlib and the multi-checker practice the community has built around AI output, is what readers need next. As a free, maintained, authoritative account of what “checked in Lean” means at the level of the logic, nothing else comes close.

Sources