Formal Verification of Fermat's Last Theorem by AI: Lessons for Engineering Large-Scale Proof Pipelines
This article breaks down what an AI formalization of Fermat's Last Theorem actually delivered: not a new theorem, but a line-by-line machine-checked expansion of an already accepted proof. It explains why a 129-page paper balloons into roughly 13.4 million lines of formal code, why correctness is not the real differentiator compared with human-maintained libraries, and how to abstract the work into a reusable pipeline of parsing, retrieval, generation, and kernel adjudication. It also covers the engineering essentials—compute budgeting, caching, parallelism, failure clustering, and observability—plus a practical action checklist for technical teams.
1. The Conclusion First: The Machine Translated and Checked, It Did Not Discover a New Theorem
The biggest misunderstanding around the discussion of “AI completing a formal proof of Fermat’s Last Theorem” comes from the headline itself. Fermat’s Last Theorem was proved by the mathematician Andrew Wiles in 1995, and another group of mathematicians later reorganized it into a version that is easier to cite. For thirty years, the mathematical community has never genuinely doubted its correctness. So what AI delivered this time was not “a proof of an unknown proposition.” Instead, it translated an argument that humans already hold with very high confidence, line by line, into a dependently typed proof assistant language (roughly, an “executable mathematical language”), and then had the proof kernel verify it step by step from the lowest-level axioms.
This distinction is critical. It fixes the coordinate system we use to judge the event: the increment in mathematical content is close to zero, while the increment in engineering and automation capability is substantial. The lead of a human-led formalization project at a university, after being “scooped,” also stated plainly that he had already been 99.9% confident the proof held, that number theorists were almost 100% certain, and that this formalization simply retraced early literature without producing anything mathematically new.
2. A Quantitative View: Why 129 Pages Swelled into Tens of Millions of Lines
Start with a few baseline numbers (used to convey the order of magnitude):
- Total formal code: about 13.4 million lines; about 10.5 million lines after removing auto-generated boilerplate;
- Final referenced theorems: 29,511;
- Local supporting lemmas: about 533,000;
- Number of files: 60,474;
- Size: about 5 times that of a general-purpose math library (a community-maintained collection of theorems);
- Compile time on a 96-core machine: about 20 times a full build of that math library.
The original paper is only 129 pages. The root of the gap is the semantic divide between “omission” and “expansion.” When humans write, they rely on a shared understanding that “every expert already knows this,” compressing intermediate steps into a single sentence. A machine accepts no default consensus; it must unfold every assumed argument into the smallest verifiable inference steps, all the way down to axioms and existing lemmas. As a result, the same proof appears as 129 pages in one medium and 13.4 million lines in the other.
This leads to a direct engineering conclusion: the main cost of formal verification lies not in “figuring it out,” but in “filling in and compiling.” Any team planning large-scale formalization should place compute budgeting, incremental compilation strategy, and cache hit rate on the same level of importance as algorithm design.
3. The Real Debate: Correctness Is Not the Difference, the Difference Is Form
The difference between the human project and the AI deliverable has been summarized precisely: there is little difference in correctness; the difference is in form. AI delivered a finished proof that was almost entirely machine-generated; the human project produced a theorem library that is not yet complete, but is written for humans to read, reuse, and maintain.
The value of a mathematical proof has never been a binary judgment of “is the conclusion right or not.” The function of a proof is to be understood by people, so that the next researcher can keep adding floors on top of the existing structure. Tens of millions of lines of machine code have indeed built the building, and the checker confirms it has not collapsed, but no human mathematician can walk inside, understand the load-bearing structure, and then extend a new floor from a particular beam.
A more practical problem is repository standards: mechanical community rules on file length, line length, docstring coverage, naming conventions, and so on would cause this artifact to be rejected wholesale at the review stage. In other words, it is a proof that can pass the proof kernel but cannot get through the door of the human mathematical community.
4. Abstracting the Event into a Reusable Technical Paradigm
Setting aside the mathematical background, this event is essentially a pipeline of “natural-language / semi-formal input → machine-checkable intermediate representation → kernel adjudication,” subjected to a stress test at the limits of very long context and a very large dependency graph. Four layers of capability can be extracted:
- Semantic parsing layer: map vague natural language and mathematical notation into strictly typed expressions; ambiguity must be resolved explicitly, with no implicit defaults allowed.
- Retrieval and dependency layer: facing nearly 30,000 theorems and more than 500,000 lemmas, retrieval quality directly determines whether the process converges; a hybrid of semantic retrieval plus symbolic indexing is a common industry approach.
- Generation and repair layer: a closed loop of generate → compile → read errors → patch, where failure messages are the only reliable supervision signal, and the number of loop rounds together with the single-round success rate jointly determine total time.
- Adjudication layer: a small, trusted kernel gives the single authoritative verdict; the generation model never acts as the judge.
Illustrative closed-loop logic (pseudocode, not a specific product interface):
def formalize(statement, env, budget):goal = parse(statement) # Semantic parsing; make ambiguity explicitfor round in range(budget.rounds):ctx = retrieve(goal, env) # Hybrid retrieval of relevant lemmascand = generate(goal, ctx) # Generate a candidate proofres = kernel_check(cand, env) # The single authoritative verdictif res.ok:return cand, res.metricsgoal = refine(goal, res.errors) # Use error messages to drive repairraise BudgetExceeded(goal)
5. Engineering in Practice: Compute, Caching, and Observability
The compilation cost of a project at the tens-of-millions-of-lines scale requires treating the build system as a first-class citizen:
- Incremental builds and caching: use content-addressed caching at file granularity; every 10% improvement in hit rate yields a roughly linear reduction in end-to-end time;
- Parallelism design: the dependency graph sets the upper bound on what can run in parallel; whether 96 cores can be fully utilized depends on the width of the graph, not the core count;
- Failure aggregation: cluster hundreds of thousands of compilation errors into a finite set of patterns, so the model does not repeatedly burn rounds on the same class of error;
- Cost attribution: measure resource consumption separately across the three stages of “retrieval / generation / compilation” to locate the bottleneck.
When implementing this in the cloud, general-purpose capabilities can carry the load: a container platform runs stateless compilation workers, object storage holds code and build artifacts, a message queue handles task distribution and failure replay, and logging plus monitoring and alerting provide real-time observation of rounds and hit rates. General-purpose capabilities from Baidu AI Cloud—containers, storage, queues, and monitoring—can support the elastic scaling and cost accounting of such high-concurrency, long-running tasks without binding to any proprietary interface.
6. An Action Checklist for Technical Teams
- Define the target form: a “deliverable finished product” or a “maintainable public asset”—the acceptance criteria for the two are completely different;
- Set standards before generating: constraints such as naming, line length, and docstrings should be built in as generation constraints, not reworked after the fact;
- Treat the kernel as the single source of truth: any model output must pass the kernel; using model self-assessment as a substitute for adjudication is forbidden;
- Design a human-readable exit: generate summaries and dependency graphs for key lemmas so humans can locate the load-bearing structure;
- Establish a regression baseline: fix the axiom set and library version to guarantee reproducibility;
- Deliver in phases: formalize the core lemmas first, then expand outward gradually, avoiding a one-shot, unreviewable dump of tens of millions of lines.
7. Conclusion
The right way to read this event is this: automated formalization can already take on the heavy work of “fully expanding and verifying an argument that humans are confident in,” but it has not yet solved the problem of being “readable, maintainable, and acceptable to the community.” For developers, the real opportunity lies not in marveling at the line count, but in organizing generation, retrieval, compilation, and adjudication into a stable, observable, cost-controlled pipeline—this is both the engineering essence of formal verification and the general skeleton of any “AI generation + machine checking” system.
