From 17 Million to 52,000 Lines: The Path to Compressing a Formal Proof

    This article examines how a formal proof of the Generalized Riemann Hypothesis was compressed from over 17 million lines to roughly 52,000 through a multi-round, cross-tool engineering effort. It explains where the bulk of formal proof volume comes from, the four main levers of compression (reuse, abstraction, automation, and proof-term sharing), and the trade-off between smaller size and readability. It also covers the complementary role of natural-language proofs, the hard lower bound on compression, three criteria for judging a successful reduction, and practical recommendations for engineering teams.

    1. The Phenomenon: A Two-Day Relay of Compression

    On November 26, 2026, a formal proof of the Generalized Riemann Hypothesis was reduced to approximately 52,000 lines. Notably, this result was not a one-off algorithmic breakthrough but an engineering achievement completed by multiple people across multiple rounds and tools: from more than 17 million lines initially, it first converged to around 300,000 lines, was then compressed to 76,000 lines, and finally landed at the 52,000-line scale. The roughly 2.4 million lines removed in two days represent only the slope at the tail end of this compression curve.

    This curve reveals a frequently overlooked fact: the size of a formal proof is determined not primarily by mathematical difficulty, but by the maturity of the infrastructure.

    2. Where the Volume Comes From: Why Formal Proofs Reach Millions of Lines

    A formal proof requires every step of reasoning to be verifiable by the kernel, so a large number of lines are consumed in three areas:

    • Building missing lemmas from scratch: When existing results in elementary number theory, complex analysis, and the theory of series and integrals are insufficient, they must be supplied manually. This part often accounts for the largest share.
    • Making types and boundaries explicit: Steps that humans write as “obvious” or “follows by continuity” must be expanded in a machine into decidable terms.
    • Lack of automation tactics: Without enough decision procedures and rewrite rules, proof scripts degrade into lengthy manual expansions.

    Therefore, 17 million lines is not “absurd”; it is more like an unorganized, self-built dependency tree.

    3. The Four Levers of Compression

    1. Reuse instead of rebuilding: Replacing self-built lemmas with existing theorems from the library is the step that reduces line count most dramatically.
    2. Abstraction and generalization: Lifting arguments about specific constants into parameterized lemmas allows a single proof to be reused in many places.
    3. Stronger automation tactics: Replacing repeated scripts with a unified decision and normalization process, as illustrated below:
    1. -- Before compression: manual expansion
    2. have h1 := step_a x
    3. have h2 := step_b h1
    4. have h3 := step_c h2
    5. ...
    6. -- After compression: a tactic closes it in one shot
    7. simp [rewrite_rules] <;> ring_nf <;> close_by
    1. Proof-term sharing: Letting intermediate results be referenced through shared structures avoids repeatedly rebuilding the same fact.

    4. The Key Trade-off: Smaller Size Does Not Mean Better Readability

    The original work noted an important observation: the 52,000-line and 76,000-line versions were actually less readable than the 300,000-line version. The reason lies in the differing nature of the compression techniques:

    • Abstraction raises the reuse rate but increases the cognitive barrier of each individual step;
    • Automation tactics replace “explicit reasoning” with “black-box closure,” making it hard for readers to follow step by step;
    • Highly parameterized lemmas require readers to perform the instantiation in their heads first.

    The engineering conclusion is that “maintainability” and “size” should be treated as dual objectives rather than a single one. It is advisable to keep a readable intermediate layer for key theorems and confine aggressive compression to the proof-script layer.

    5. Natural-Language Proofs: Another Dimension of Evaluation

    During the same period, a 322-page natural-language proof appeared, which was then further compressed to 43 pages in English and 38 pages in Chinese, accompanied by a 56-page formalization companion document. This shows that natural-language versions follow the same compression pattern, and that the two are complementary: the natural-language version handles “why it holds,” while the formal code handles “that it indeed holds.” In a review workflow, the former lowers the cost of understanding, while the latter provides a machine-verifiable root of trust.

    6. How Small Can It Get: Lower Bounds and Criteria

    The remaining room for compression comes mainly from three areas: making the remaining self-built lemmas common, turning repeated scripts into tactics, and refining shared structures at a finer granularity. But there is a hard lower bound—the irreducible core argument beyond the referenced base library cannot disappear. The so-called “one-line version” essentially moves all the work into external dependencies; it is a change in the measurement basis, not real compression.

    To judge whether a compression is successful, three criteria can be used: the kernel check passes, the key lemmas can still be reviewed independently, and the size reduction is not accompanied by proof strategies becoming unexplainable. If all three cannot be satisfied simultaneously, it is better to keep the size.

    7. Practical Recommendations for Engineering Teams

    • First build a dependency inventory to identify the boundary between self-built lemmas and existing results;
    • Advance compression in the order “reuse → abstraction → automation,” avoiding black-box tactics from the outset;
    • Use continuous integration to run machine checks on each compression, preventing “the more you compress, the more errors you introduce”;
    • Track size and readability separately, keeping a readable layer for core conclusions;
    • Maintain natural-language and formal tracks in parallel, decoupling review from verification.

    This methodology for large-scale code reduction is highly analogous to dependency governance, duplicate-code elimination, and build-cache reuse in everyday software engineering; in a cloud environment, container platforms, object storage, and logging services can host the verification pipeline and version history, making the compression process reproducible and traceable.