STACKDUST
AR
Anthropic research visual showing geometric curves and protractor for Fermat's Last Theorem formalization

Claude Formalizes Fermat's Last Theorem in Lean 4: 13 Million Lines of Machine-Checked Proof


Machine-Checked Proofs at Scale: Claude Formalizes Fermat’s Last Theorem

Pierre de Fermat’s 1637 marginal note in Diophantus’s Arithmetica asserted that no three positive integers a, b, and c can satisfy the equation aⁿ + bⁿ = cⁿ for any integer value of n greater than 2. For more than 350 years, the assertion stood as one of the most stubborn conjectures in pure mathematics until Sir Andrew Wiles published a 129-page proof in 1995, with contributions from Richard Taylor. Verifying Wiles’s proof required months of scrutiny from leading arithmetic geometers because human mathematical discourse routinely omits intermediate algebraic identities, geometric definitions, and modular arithmetic lemmas that human reviewers are expected to reconstruct from context.

Transforming that human paper into a machine-checked formal proof in an interactive theorem prover like Lean 4 has historically required multi-year human research campaigns. In 2024, Kevin Buzzard at Imperial College London launched an international community effort to formalize Wiles’s proof using Lean. The blueprint mapping out just the initial structural prerequisites spanned 86 pages of intermediate definitions, and arithmetic geometers projected that complete machine verification would require years of focused human labor.

On September 4, 2026, Anthropic published results showing that an autonomous multi-agent swarm directed by researcher Tianyi Peng completed the first end-to-end, computer-checked proof of Fermat’s Last Theorem in 11 days. Working within Prove2Me, an open collaborative formalization platform developed at Columbia University, dozens of Claude agents coordinated to generate 13 million lines of Lean 4 code, proving 29,500 distinct intermediate lemmas and theorems verified directly by the Lean kernel without human intervention.

Wiles-Taylor Modular Proof (1995)
  | 129 pages of human arithmetic geometry (Frey curves, Ribet's theorem, Shimura-Taniyama)
  v
Lean Community Formalization Blueprint (2024)
  | 86-page architectural blueprint led by Kevin Buzzard
  v
Claude Multi-Agent Swarm on Prove2Me (2026)
  +-------------------------------------------------------------------------+
  | Orchestration: Claude Code agent harness + Prove2Me DAG coordinator     |
  | Compute: ~6 billion output tokens (research model on par with Fable 5.1)|
  | Duration: 11 calendar days of autonomous iteration                      |
  +-------------------------------------------------------------------------+
  |
  +---> 30,300 candidate lemmas generated
  +---> 29,500 intermediate theorems verified in Lean 4
  +---> 13,000,000 lines of Lean 4 code produced
  v
Lean 4 Micro-Kernel Verification: Root Theorem "FLT" reads PROVED

Why Mathematical Formalization Breaks Standard Agent Architectures

Large language models have frequently stumbled when applied to research-level mathematics. When prompting an LLM in natural language or LaTeX, models suffer from hallucinated lemmas, circular reasoning, and hand-waving transitions where complex steps are smoothed over with phrases like “it clearly follows that.” Because natural language lacks an objective runtime execution environment, evaluating whether an LLM’s proposed proof is sound requires human experts to pore over every line.

Interactive proof assistants like Lean 4 alter this dynamic by providing an unforgiving, deterministic compiler. A proof in Lean is not an essay; it is a program typed in dependent type theory (the Calculus of Inductive Constructions). Lean’s microkernel accepts a theorem as true if and only if the developer constructs a valid term of the corresponding type:

-- Classical statement of Fermat's Last Theorem in Mathlib
theorem fermat_last_theorem (n : ℕ) (hn : n > 2) :
    ¬ ∃ (a b c : ℕ), a > 0 ∧ b > 0 ∧ c > 0 ∧ a^n + b^n = c^n := by
  sorry

Every single deduction, definition, and rewrite must resolve against Lean’s foundational axioms. If an agent hallucinates a step or attempts an invalid algebraic simplification, the Lean compiler throws a deterministic type error. However, this strictness created a severe bottleneck for naive agent loops. When early LLM agents interacted with Lean via standard conversational loops, they suffered from context collapse. Agents proved a localized lemma, failed to persist dependency references across subgoals, and lost track of the overarching proof graph. In early Anthropic trials, uncoordinated agent runs disintegrated within hours, generating redundant code that accounted for approximately 7 percent of non-boilerplate lines in the final codebase.

The Multi-Agent Swarm and the Prove2Me Protocol

The breakthrough occurred when Anthropic shifted from single-agent conversational loops to a decentralized multi-agent harness managed through Prove2Me. Originally designed by Tianyi Peng and collaborators at Columbia University, Prove2Me functions as a distributed dependency graph for formal mathematics.

Instead of treating the 129-page proof as a single monolithic context window, Prove2Me deconstructed the campaign into a directed acyclic graph (DAG) of intermediate mathematical targets based on the Darmon, Diamond, and Taylor exposition of Wiles’s proof:

  1. Topological and Scheme Definitions: Formulating modular curves, Jacobians as schemes, and Galois representations over local fields.
  2. Intermediate Lemma Proving: Proving individual algebraic number theory lemmas (such as class number bounds and Mazur’s theorem on torsion points).
  3. The R=T Theorem: Establishing the isomorphism between the universal deformation ring (R) and the Hecke algebra (T), which forms the structural core of the modularity lifting mechanism.
  4. Root Cascading: Compiling proved subgraphs and feeding their type signatures into upstream proof obligations until the root theorem resolves.
Prove2Me Directed Acyclic Proof Pipeline:
[ Root: Fermat's Last Theorem ]
      ^
      |-- [ Modularity Lifting: R = T Isomorphism ]
      |         ^
      |         |-- [ Universal Deformation Rings ]
      |         +-- [ Hecke Algebras on Modular Forms ]
      |
      |-- [ Frey Curve Construction & Ribet Level-Lowering ]
      |         ^
      |         |-- [ Galois Representations ρ: Gal(Q̄/Q) -> GL₂(F_p) ]
      |         +-- [ Mazur's Torsion Theorem in Lean ]
      |
      +-- [ Base Arithmetic: Flach Euler Systems & Local Fields ]

Individual Claude instances, orchestrated via an internal agent harness derived from the architecture detailed in the Claude Agent Stack GA release, were assigned specific sub-nodes in the DAG. When an agent attempted a lemma, it drafted Lean tactics, executed the Lean compiler in an isolated container, and read compiler error traces directly. If Lean rejected a tactic, the agent refined its derivation. Once Lean confirmed a proof with zero sorry markers, Prove2Me locked the node, published its type signature, and marked dependent theorems ready downstream.

Across 11 days of continuous autonomous execution, the swarm consumed approximately six billion output tokens from an internal frontier research model with capabilities aligned with the tier established in the Claude Fable 5.1 launch. The campaign peaked on August 17 at 10:00:57 PM ET (02:00:57 UTC August 18), when node 62eb32c0 (the R=T core closure) cascaded to the root node, and Prove2Me registered the root theorem as fully proved.

Verification, Mathlib Comparison, and Independent Review

To ensure the proof did not rely on unsound axioms or circular shortcuts, Anthropic subjected the 13-million-line repository to independent validation:

  • Axiomatic Purity: The entire proof was verified using only Lean’s three foundational standard axioms (propositional extensionality, quotients, and the axiom of choice). No custom axioms or unverified foreign constants were introduced.
  • Statement Matching: An automated AST comparator verified that the formalized theorem statement in Claude’s root file matched the canonical statement of Fermat’s Last Theorem defined in Mathlib, eliminating the possibility of semantic drift where a model inadvertently proves an easier trivial statement.
  • External Mathematician Scrutiny: Anthropic shared the complete Lean code and AST graph with Kevin Buzzard, who heads the community FLT formalization initiative. Buzzard confirmed that the agent swarm had successfully formalized the Darmon-Diamond-Taylor formulation of the proof.

At 13 million lines of Lean 4 code, the generated proof is more than five times larger than the entire community Mathlib repository. Much of this volume stems from Claude’s tactic expansion: where human formalizers spend weeks searching for elegant, concise tactic combinators to compress a 500-line lemma into 20 lines, Claude’s agents generated exhaustive, step-by-step constructive proof steps that Lean checks in milliseconds.

Token Economics and Consumer Hardware Scaling

While formalizing Fermat’s Last Theorem required six billion tokens, Anthropic evaluated whether collaborative formalization could scale down to standard developer tooling. Using three personal Claude Max subscriptions connected to Prove2Me, researchers tasked a three-agent swarm with formalizing Vinogradov’s Three Primes Theorem (every sufficiently large odd integer can be written as the sum of three primes) using the Hardy-Littlewood Circle Method.

Working autonomously across 72 hours, the three consumer-tier agents completed the formalization of Vinogradov’s theorem in Lean 4 without custom fine-tuning or dedicated supercomputing infrastructure.

Formalization Campaign Comparison:
+------------------------------+-------------------------+-------------------------+
| Metric                       | Fermat's Last Theorem   | Vinogradov Three Primes |
+------------------------------+-------------------------+-------------------------+
| Duration                     | 11 calendar days        | 3 calendar days (72h)   |
| Output Volume                | 13,000,000 lines Lean 4 | 420,000 lines Lean 4    |
| Verified Theorems / Lemmas   | 29,500 lemmas           | 1,180 lemmas            |
| Agent Fleet Architecture     | Dozens of Claude agents | 3 Claude Max instances  |
| Coordination Layer           | Prove2Me + Claude Code  | Prove2Me + Claude Code  |
| Human Intervention Frequency | High-level steering only| Zero intervention       |
| Axioms Used                  | Standard Lean 3 axioms  | Standard Lean 3 axioms  |
+------------------------------+-------------------------+-------------------------+

Architectural Limitations and Next Steps

Despite the historic milestone, the formalization run surfaced distinct structural limitations:

  1. Proof Verbosity and Maintainability: The resulting 13-million-line codebase is machine-verifiable but largely unreadable for human mathematicians. Future work must incorporate automated proof refactoring and tactic minimization to distill verbose tactic dumps into concise Mathlib-ready pull requests.
  2. Proof Discovery vs. Formalization: Claude did not discover a novel proof for Fermat’s Last Theorem; it translated an existing 1995 mathematical proof into formal logic. Discovering novel mathematical strategies remains significantly harder than translating human mathematical literature into computer code.
  3. Compiler Compute Bottlenecks: Checking 13 million lines of Lean 4 code stresses CPU memory caches. Running CI checks across the full proof tree requires distributed build clusters to prevent compiler timeouts.

The successful completion of the Fermat formalization demonstrates that the primary bottleneck in formal mathematics is no longer the manual transcription of proof steps into code. By marrying deterministic compilers with multi-agent coordination frameworks, formal verification is shifting from a multi-year academic endeavor into an automated continuous integration pipeline for human mathematical knowledge.

Sources


Next ArticleMinusPod: Self-Hosted Audio Pipeline That Strips Podcast Ads Using Whisper and Local LLMsPrevious Articlecua-driver: Background-First Desktop Automation and Multi-Tier Accessibility for AI Agents