AI Formalizing Fermat's Last Theorem: Engineering Lessons from 13 Million Lines of Lean Code

    This article examines the recent machine formalization of Fermat's Last Theorem in Lean, clarifying what the project actually achieved and what it did not. It breaks down the scale of the effort with concrete metrics, summarizes the debate over whether a kernel-verified proof counts as a good proof, and draws practical lessons for engineering teams building AI-generated or formally verified software—especially the difference between passing verification and delivering a maintainable, evolvable asset.

    1. Clearing Up a Misconception: This Is Not a Mathematical Breakthrough

    The theorem was already proven; formalization is not discovery

    Fermat’s Last Theorem—the claim that the equation $x^n + y^n = z^n$ has no positive integer solutions when $n > 2$—was proved by British mathematician Andrew Wiles in 1995. For nearly thirty years since, the mathematical community has never seriously doubted its truth. So the recent AI work is not “the discovery of a new theorem.” It is the complete migration of an existing, peer-reviewed classical argument into a formal system that a proof assistant can verify.

    This distinction matters. It moves the discussion away from the grand question of “Can AI do mathematics?” and toward a more concrete and measurable engineering problem: Can a loose argument that relies on a large body of “expert assumptions” be compressed into an unambiguous chain of reasoning that a kernel can check line by line?

    Which version was formalized, and how

    The formalized argument is typically based on Wiles’s original work and later consolidations by researchers such as Darmon, Diamond, and Taylor. The essence of the formalization effort is to “re-walk” an established path through the mathematical literature. Its output adds nothing new at the level of mathematical knowledge—a point even the academics who launched the human-oriented formalization project openly acknowledge: the correctness is agreed upon; only the form differs.

    2. Understanding the Real Scale of the Engineering Through Data

    To grasp the engineering difficulty here, you have to look at quantitative metrics rather than the conclusion itself:

    Metric Scale Notes
    Total Lean code ~13.4 million lines ~10.5 million lines after removing auto-generated boilerplate
    Theorems invoked in the final proof 29,511 Drawn from the math library and prior formalization results
    Supporting local lemmas ~533,000 Auxiliary propositions supporting the main line
    Files involved 60,474 Extremely fine-grained engineering organization
    Size relative to the existing math library ~5x Far beyond a typical single formalization project
    Compilation time ~20x the math library on a 96-core machine The cost of line-by-line kernel checking

    The comparison is even more striking: Wiles’s original paper is only 129 pages long. Human experts systematically omit intermediate steps that “every peer already understands,” summarizing an entire argument in a single sentence. Machine formalization, by contrast, must expand every assumed step into a minimal, checkable inference. The same proof therefore balloons into tens of millions of lines of code—what has expanded is not the mathematical content, but the form’s unforgiving demand for explicitness.

    3. The Core Debate: Does a Proof That Passes the Kernel Equal a “Good Proof”?

    “Same correctness, different form”

    The sharpest criticism of this delivery comes from academic teams who have long advanced human-oriented formalization projects. Their core view can be summarized as: “There is no difference in correctness; the difference is only in form.” One side delivered a finished proof generated almost entirely by machine; the other is building an unfinished but human-readable, reusable, and long-term maintainable math library.

    The dual value of a proof: verification and understanding

    The traditional view treats a proof as a binary judgment of “is the conclusion correct,” but the real needs of the mathematical community go further. A proof must be readable by the next person so that new theorems can be stacked on top of existing results. Measured against this standard:

    • The tens of millions of lines of machine code successfully “built the building” and proved it will not collapse;
    • But no human mathematician can walk into that building and see its load-bearing structure;
    • And no one can continue building a new level upward along a particular beam.

    The practical gap at the level of engineering standards

    If this kind of deliverable were checked against the common contribution standards of mainstream math libraries—file length, line length, completeness of docstrings, naming consistency, structural organization, and so on—it would most likely be rejected outright. In other words, it is a proof that “passes the proof kernel’s check but cannot get through the door of the human mathematical community.” This is not a quality problem but a misalignment of delivery goals: one is optimized for machine verifiability, the other for human evolvability.

    4. Lessons for Engineering Teams: Verifiability ≠ Maintainability

    This has direct relevance for teams doing AI-automated delivery. When large models are applied to code generation, formal verification, or building complex systems, it is easy to fall into a trap: treating “does it pass the checker?” as the sole measure of success.

    A mature quality-assessment framework should include at least three dimensions:

    1. Correctness: Does it pass the formal kernel or the test suite? This is the baseline, but far from the finish line.
    2. Maintainability: Is the structure clear, is naming consistent, is documentation complete? This determines whether the team can take over the artifact long term.
    3. Evolvability: Can newcomers continue development on top of existing results at low cost? This is the dividing line between a “one-off delivery” and a “reusable asset.”

    When a cloud provider offers capabilities such as intelligent coding tools, container platforms, log services, and monitoring and alerting, it faces similar trade-offs: automation greatly increases delivery speed, but engineering governance (standard constraints, review processes, documentation accumulation) must keep pace—otherwise what accumulates is only “code that passes CI,” not “a genuine asset for the team.”

    5. Conclusion

    The machine formalization of a classical conjecture by AI is a powerful demonstration of the capabilities of automated reasoning and formalization engineering. It shows that current technology already has the organizational capacity to handle extremely large-scale formalization tasks. But packaging it as “AI proved Fermat’s Last Theorem” is both inaccurate and obscures the engineering issues that are actually worth discussing.

    For developers, the more valuable lesson to absorb is this: distinguish “verification passed” from “delivery succeeded.” The value of any automatically generated artifact ultimately depends on whether humans can understand it, take it over, and keep building on it. The next leap in technical capability will not come from making machines write more lines of code, but from making what machines write both correct and worth maintaining by humans over the long term.