Formal Verification of Fermat's Last Theorem by AI: A Technical Breakdown
This article breaks down a recent milestone in which an AI agent system completed an end-to-end formal verification of Fermat's Last Theorem in about 11 days. It explains what "verified" actually means, why the 13 million lines of formal code differ fundamentally from the 129-page human proof, how roughly 29,500 lemmas were chained into a single dependency graph, and the engineering architecture behind multi-agent collaboration. It also covers cost structure, common misconceptions, and practical recommendations for enterprises adopting formal verification pipelines.
1. What Happened: A Proof Chain Checked Down to Its Root
A cloud provider recently announced that its AI coding agent completed an end-to-end formal verification of Fermat’s Last Theorem in about 11 days with minimal human intervention. This is not “a machine understanding mathematics.” It is an engineering milestone: for the first time, a complete formal chain leading to a final proposition was checked by a computer layer by layer from its premises down to the root node, with the final state marked as passed.
The publicly shared figures are roughly as follows: a cycle of about 11 days, approximately 13 million lines of formal code produced, about 30,300 auxiliary theorems constructed and proved along the way, roughly 29,500 of them actually referenced by the final chain, and about 6 billion tokens output in total. The work was not done by a single model but by a collaborative system made up of dozens of agents, auxiliary proof search tools, and an interactive theorem prover.
Three boundaries must be drawn first, or the conclusion is easy to overstate:
- No new mathematical proof was produced. It followed a simplified route already established in academia, a rewrite and restatement of the classical proof.
- It is not a sentence-by-sentence translation of the original paper. The human paper is 129 pages; the formal artifact is 13 million lines. They are not the same kind of text.
- It was not a one-shot output from a single model. It is the result of a system combining scheduling, retrieval, caching, parallel trial and error, and failure rollback.
2. What “Verified” Actually Verified
The proposition of Fermat’s Last Theorem is simple: when the integer n is greater than 2, the equation xⁿ + yⁿ = zⁿ has no positive integer solutions. The human proof was announced in 1993, then found to contain a critical gap; after the gap was patched, it was formally published in 1995, with a main paper of 129 pages.
The object of formal verification is not “whether the idea is correct” but “whether every step of the derivation can be mechanically derived from basic rules.” A phrase like “it is obvious that” in a human paper must be spelled out in a proof assistant: what type the mathematical objects involved are, which existing theorems are allowed to be used, and what justifies each intermediate substitution. If any step is left unclear, the checker fails at that point.
So the precise meaning of “verified” is this: the entire dependency chain, from the axioms and existing libraries to the final proposition, passed the kernel’s mechanical check. Its strength is higher than “many people have read it and agree,” because it is repeatable and its result is deterministic. But it does not cover “whether this route amounts to discovering new mathematics,” which is a separate dimension.
3. 129 Pages vs. 13 Million Lines: Two Texts Solving Two Kinds of Problems
| Dimension | Human paper | Formal script |
|---|---|---|
| Goal | Convey understanding and intuition | Provide mechanically checkable content |
| Omission strategy | Omits shared background, compresses routine derivations | No omission allowed; a gap means failure |
| Source of trust | Peer review, test of time | Kernel checking, repeatable runs |
| Reuse | Reading and re-derivation | Directly referenced by later proofs |
| Main cost | Reading barrier and attention | Construction and dependency maintenance |
The key insight is that the value of 13 million lines lies in coverage, not in length itself. Public information also makes clear that this artifact is very likely far longer than necessary, reaching more than five times the size of a general mathematics library. It is an engineering artifact of remarkable completeness, not the concise version a human would pursue. The two kinds of text therefore will not replace each other: the paper lets people see the line of thought; the script lets the check be executed repeatedly.
4. How 29,500 Theorems Were Chained Into One Path
The most common failure mode in long proofs is not “a step is too hard” but loss of control over dependencies. Five practices make this tractable:
- Make dependencies explicit. Each lemma declares which prior results it references, forming a directed acyclic graph; implicit dependencies are forbidden.
- Advance in layers. Organize by “basic algebra — number theory tools — intermediate structures — final assembly,” so each layer can be compiled and accepted independently.
- Commit in small steps. Break a large goal into lemmas that can be checked independently, so a single-point failure does not affect global progress.
- Cache and increment. Persist and reuse results that have already passed to avoid repeatedly consuming compute; treat “verified” as an addressable asset.
- Surface conflicts early. When working in parallel, run periodic full integration checks to prevent interface drift from accumulating until the end.
A schematic dependency manifest can be expressed as structured data, making it easy for tools to perform topological sorting and incremental validation:
{"target": "final_theorem","depends_on": ["lemma_level_3", "lemma_modularity"],"status": "verified","proof_terms": 29500,"cache_key": "sha256:..."}
5. The Engineering Skeleton of a Multi-Agent Collaboration System
Putting this kind of task onto a runnable system usually involves six layers:
- Scheduling layer: handles task decomposition, prioritization, and concurrency control, preventing dozens of execution units from stepping on each other.
- Strategy layer: maintains a library of proof strategies and common failure modes, switching paths when stuck rather than hammering at one approach.
- Retrieval layer: locates reusable lemmas from the formal mathematics library to avoid reinventing the wheel.
- Execution layer: multiple execution units try different proof paths in parallel, and success is solidified immediately.
- Verification layer: the proof assistant kernel makes the final judgment, accepting only artifacts that pass.
- Observability layer: records token consumption, distribution of failure causes, and pass rates at each layer.
When deployed on the cloud, this can be carried by composing general-purpose capabilities: a container platform provides isolated execution environments, object storage holds proof artifacts and caches, a message queue decouples scheduling from execution, and logging plus monitoring and alerting handle observability for long-running tasks. Baidu AI Cloud typically supports such scenarios with the general capability categories above, giving long-cycle, high-concurrency verification tasks elasticity and traceability.
6. Cost Structure and Common Misconceptions
The 6 billion output tokens show that the cost lies mainly in “trial and error” rather than “generation.” The optimization direction is therefore not compressing a single output but raising the first-pass success rate:
- Misconception 1: treating line count as quality. Line count only reflects the degree of expansion, not conciseness.
- Misconception 2: treating passing as discovery. Passing only means the derivation is valid, not that the route is novel.
- Misconception 3: ignoring reproducibility. Without version-pinned libraries and environments, results cannot be rerun.
- Misconception 4: underestimating maintenance cost. A dependency upgrade may cause already-passed parts to fail again.
7. Practical Recommendations for Enterprises
- Start with a small-scale pilot. Pick a specification with clear boundaries that can be mechanically checked, and validate the stability of the pipeline.
- Pin dependency versions and the execution environment, and make “rerunnable” a hard acceptance criterion.
- Establish layered acceptance and cache reuse mechanisms to control the compute curve of long-cycle tasks.
- Bring formal artifacts into regular artifact management, with review, archiving, and rollback just like code.
- Be clear about capability boundaries: formalization solves “whether the derivation is valid” and does not replace requirement judgment or architecture decisions.
8. Conclusion
The real signal from this event is not “AI can do math problems” but that the engineering barrier to formal verification is falling: an extremely long proof chain can now be automatically constructed, automatically checked, and automatically archived by a system. For developers, the transferable lessons are making dependencies explicit, advancing in layers with small steps, reusing caches, and keeping the whole chain observable. This methodology applies to any scenario where “conclusions must be mechanically reviewable.”
