Formal Verification with AI: 194,000 Lines of Lean Code Uncover a 13-Year-Old Arithmetic Error
This article examines how a large-scale formalization effort in Lean 4, covering approximately 194,000 lines of code with zero admitted goals, verified the ternary Goldbach conjecture and exposed at least eleven inconsistencies in the original proof materials. It explains the major arcs versus minor arcs structure of the Hardy–Littlewood circle method, the specific constant corrections uncovered during review, and the practical engineering implications of a zero-sorry workflow, including layered proof design, specification-first development, and running proofs as a continuous integration pipeline. Engineers and technical teams will find a transferable methodology for moving long, calculation-heavy arguments into machine-checkable, reproducible, and auditable form.
1. Why This Matters: From “Published Is Done” to “Machine-Verifiable Is Trustworthy”
In the traditional mathematics publishing model, the correctness of a proof rests primarily on peer review and author reputation. Reviewers sample key lemmas, re-check the main logical line, confirm there are no obvious gaps, and then accept the paper for publication. But this model develops systemic weaknesses when faced with extremely long, highly detailed, computation-intensive proofs: reading costs accumulate over time, reproduction costs approach the cost of redoing the derivation entirely, and errors are very hard to localize quickly once they occur.
The core value of this event is that it migrated the “ternary Goldbach conjecture” (the weak Goldbach conjecture, which states that every odd number greater than 5 can be expressed as the sum of three primes), a classic result, fully into a formal proof environment and verified it statement by statement with a machine. This means the result is no longer merely “a conclusion announced in a paper in some year,” but a “computational asset” that anyone can independently re-run, independently audit, and independently inherit.
For engineering teams, the lesson from this shift is direct: any argument or process on the critical path that is “long, slow, expensive, and hard to re-check” is a candidate for formalization, automation, and continuous verification. Mathematical proofs are simply the most extreme sample. The security argument for cryptographic protocols, proofs of distributed consistency, compiler correctness proofs, and compliance audits of financial risk-control rules all follow the same logic.
2. Why the Original Proof Is Hard to Check: Major Arcs as “Revenue,” Minor Arcs as “Overhead”
The standard proof route for the ternary Goldbach conjecture typically follows the Hardy–Littlewood circle method framework, which splits the problem into two main regions: major arcs and minor arcs. Intuitively, this can be understood as “revenue versus overhead”:
- Major arcs: the frequency regions with good approximations and strong structure, which contribute the “main term” and can be viewed as revenue;
- Minor arcs: the frequency regions that are pseudo-random and strongly oscillatory, where one must prove their perturbation to the whole is small enough, viewed as overhead;
- The final goal: prove that the main term (revenue) reliably exceeds the perturbation term (overhead), thereby guaranteeing that a representation exists.
The difficulty lies in the fact that arguments of this kind often rely on large amounts of explicit inequality bounding, integral estimates, exponential sum bounds, constant computations, and case-by-case handling. The human eye can grasp the main line, but at a scale of hundreds of pages it is hard to guarantee statement by statement that every constant is correct, every branch is seamless, and every condition is fully covered. Especially when a constant is miswritten or an inequality fails in a certain parameter range, the subsequent derivation may still “look reasonable,” but the conclusion chain has already been contaminated.
3. The AI-Assisted Engineering Approach: 194,000 Lines of Lean Code and “Zero Sorry”
In this publicly documented engineering effort, the developers broke the proof goal down into subgoals that could be formalized step by step, and used intelligent coding tools to complete the vast majority of the Lean 4 formalization code, automation scripts, and documentation. The final codebase reached a scale of about 194,000 lines and achieved “zero sorry.”
Here, sorry is a placeholder in interactive theorem-proving languages such as Lean that means “this step has not yet been proven.” Zero sorry does not mean “the AI wrote more code.” It means:
- every theorem declaration has a proof term that can be machine-checked;
- there is no hidden debt of “skip now, fill in later”;
- the entire conclusion chain closes under the formal system’s kernel, with no unproven gaps tolerated by human acquiescence.
For software engineering, this is equivalent to upgrading a codebase that is “full of TODO/FIXME but runs” into a system where “every line has passed compile-time strong verification.” The difference is that the latter’s correctness guarantee comes from a mathematical kernel, not from a statistical probability measured by test coverage.
Illustrative project structure (not a specific implementation):
project/proofs/ # Layered formal theorems and lemmasanalytic/ # Analytic number theory, exponential sum estimatesarcs/ # Major/minor arc partition and estimatesarithmetic/ # Arithmetic constants, explicit boundsscripts/ # Automated build, batch verificationdocs/ # Proof structure notes, mapping to the original paperREADME # Error list, fix records, reproduction steps
Under this structure, “reproduction” no longer depends on the author’s verbal explanation or email attachments. Instead, it looks like this:
# Pseudocode: continuous-verification buildbuild_check() {verify_all_theorems --no-sorrycompare_constants --against paper_v1report_discrepancies --output errors.md}
4. The Most Damaging Problems Are Often Not “Logical Leaps” but “Arithmetic Slips”
Publicly available information mentions that the formal review found at least 11 inconsistencies with the original materials. The most representative ones include: a key constant was written as 0.5 in the original expression, while the correct value should be 0.8102; after related fixes, the project ultimately adopted 0.8764. There were also cases where “a certain inequality did not hold under certain premises.”
These kinds of errors are very typical in an engineering context: they are not “the idea is wrong,” but “a parameter is miswritten,” “a boundary case is not covered,” or “a condition is not strong enough.” Once they enter a formal environment, the problems are immediately exposed as:
- type mismatches;
- goals that cannot be proven;
- proof terms that fail to close;
- the need for additional lemmas or stricter conditions.
The corresponding repair strategies also show a highly engineering-oriented character:
| Error type | Typical peer-review problem | Behavior in a formal environment | Repair approach |
|---|---|---|---|
| Wrong constant | Hard to catch by sampling | Goal fails to close | Trace back the derivation, recompute explicit bounds, update the dependency chain |
| Inequality too strong | Main line looks reasonable | Some condition branches cannot be proven | Weaken the proposition or add premises |
| Missing boundary case | Often glossed over as “obvious” | Requires explicit case analysis | Fill in finite cases / limiting cases |
| Variable range drift | Easy to miss across chapters | Type/constraint check fails | Unify the variable domain and assumptions |
This illustrates a key fact: the greatest value of AI in complex proofs is not only “writing faster,” but “zero tolerance for errors.” It will not rationalize an error for you as “the author obviously knows,” but will force you to fix it into a verifiable truth.
5. Methodology: How to Move an “Extremely Long Argument” into Verifiable Engineering
For teams that want to reuse this methodology, it can be abstracted into a four-step process:
5.1 Specification First: Write Down “What to Prove” as Machine-Understood Goals
Do not directly ask a tool to “help me prove a paper.” You should first decompose the conclusion into a set of theorem declarations that can be independently verified, making explicit each lemma’s assumptions, conclusions, and dependencies. The quality ceiling of a formal proof is often determined by the quality of the goal decomposition.
5.2 Layered Progression: Break 300 Pages into “Compilable Units”
Divide the proof into modules such as arithmetic, analytic, combinatorial, and boundary layers, each of which can be built and verified independently. This way, when something fails, you can quickly locate whether it is a constant problem, an estimation problem, or a structural partition problem.
5.3 Continuous Verification: Run Proofs Like CI
Plug the formalization build into a continuous integration pipeline:
# Pseudo-config: proofs should run CI toopipeline:- stage: verifycommand: lean_build --strict --no-sorry- stage: auditcommand: check_dependencies --map-paper- stage: reportcommand: generate_proof_trace
Its value is that whenever a lemma is added or a constant is fixed, the system automatically regresses the whole chain, avoiding “fix one place, break a whole area.”
5.4 Error Closed-Loop: Turn Discovered Inconsistencies into an Asset
List the differences between the original paper and the formal code (such as a constant mapping table, a condition comparison table, and a failing-case table), forming a knowledge base that can be inherited. This not only raises the current project’s credibility but also provides a low-cost entry point for subsequent version updates, peer reproduction, and teaching use.
6. Implications for Enterprises: Trustworthiness Is Becoming a Core Competency
In finance, healthcare, energy, transportation, aerospace, basic software, and other domains, the largest cost is often not “building it,” but “proving that it is correct.” The traditional approach relies on expert review and document handoff, but experts are scarce, time is expensive, and knowledge is lost quickly. Formal verification combined with intelligent coding tools is transforming “correctness” from tacit experience into explicit engineering assets.
Directions enterprises can act on include:
- Critical algorithm compliance audits: formalize risk-control rules, pricing logic, and clearing processes, automatically detecting missing conditions and boundary errors;
- Protocol and system security: produce machine-verifiable proofs for critical protocols such as authentication, authorization, and consensus;
- Compilers and database kernels: incorporate correctness proofs into the development process to reduce regression risk;
- R&D knowledge transfer: upgrade “why it is written this way” from comments into verifiable propositions, reducing the understanding gap caused by staff turnover.
7. Conclusion: This Does Not Replace Mathematicians, It Upgrades the “Trustworthy Production Method”
The result of 194,000 lines of formal code with zero skipped steps shows that AI can now deeply participate in high-difficulty, long-chain, strongly verified tasks. What it brings is not “proof outsourced,” but “correctness industrialized.” The mathematician’s intuition still provides the key ideas and structure, but AI and formal tools are responsible for polishing the ideas into unambiguous, reproducible, and auditable facts.
For developers, the real action guide is not asking “will AI write code,” but restructuring your workflow:
- Change “I think it is correct” into “I can prove it is correct”;
- Upgrade “review sampling” to “full machine verification”;
- Upgrade “document description” to “executable specification”;
- Move “fix after the fact” forward into “continuous verification.”
Only when correctness itself can be automatically proven and automatically regressed will the trustworthiness of software and algorithms, for the first time, truly reach engineering scale.
