Formal Proof Compression: Why a Million-Line Proof Shrinks to 76K Lines Yet Produces Larger Verification Data

    This article examines the compression of very large formal proofs and clarifies three distinct metrics hidden behind the question "how big is a proof": source lines of code, the size of the proof terms expanded during machine checking, and the length of an argument that humans can review. It traces the main sources of bloat—imported dependencies, repeated wrappers, and auto-generated helper lemmas—and presents slimming strategies such as modular reuse, proof term sharing, caching, and layered verification. It also explains why shorter source code can produce larger checking data, giving readers a reusable framework for measurement and optimization.

    1. A Counterintuitive Starting Point: Lines of Code Are Not the Only Measure of Length

    A recent engineering event drew wide discussion: a formal proof of theorems related to the Riemann hypothesis, generated by an AI coding tool, was cut by roughly 2.4 million lines through global collaboration in a very short time. The original version contained about 175,000 files and about 17 million lines. The compact version later made public was about 76,000 lines, and the readable version was about 300,000 lines. Both shortened versions covered only the five target theorems listed in the original.

    What deserves developers’ attention is not the number game itself, but why the same proof can exist in three “lengths” that differ by two orders of magnitude. The answer is that they measure completely different objects.

    • Source size: the instruction text written by humans and interpreted by the proof assistant.
    • Expanded proof terms: the objects the machine actually checks; one short instruction in the source can expand into enormous amounts of data.
    • Reviewable argument: the detail a mathematician needs in order to read and check the chain of reasoning.

    In a public independent verification, the compact version exported about 5.17 GB of proof data, while the readable version exported about 4.49 GB. The set with the shorter source handed the checker more data. This result is the key to understanding the whole problem.

    2. Where the Bloat Comes From: Four Sources of “Water” in Formal Engineering

    Bloat in formal code resembles and differs from bloat in business code. The main sources fall into four categories.

    The first is imports and dependencies. Large-scale proofs are usually built on top of a base library, and import declarations, namespaces, and cross-module references bring in many lines that appear to carry no content. Whether content already inside the library is counted in the total directly changes the conclusion.

    The second is repeated wrappers. To unify interfaces, developers often wrap existing lemmas in a thin layer. Such wrappers are extremely cheap during rapid iteration but add up to a considerable amount.

    The third is auto-generation and automation scripts. Batch-generated helper lemmas and boilerplate produced by scripts often account for the bulk of the code, and humans almost never read them line by line.

    The fourth is the style of “helping the system find intermediate steps.” To make an automation tactic succeed, you must explicitly supply intermediate quantities, rewrite directions, and case-split hints. These lines are scaffolding for the machine and noise for humans.

    Schematically, the boundary between bloat and what can be slimmed looks roughly like this:

    1. Original project
    2. ├── Imports and namespaces -> can be pushed down into a shared library
    3. ├── Thin wrapper layers -> can be folded in batches
    4. ├── Auto-generated lemmas -> can be rebuilt on demand by scripts
    5. ├── Tactic intermediate hints -> can be replaced by stronger automation
    6. └── Core proof of the targets -> must be kept

    3. Why Shorter Source Produces Larger Verification Data

    The reason is that the two lengths use different units. Source measures “instruction characters,” while proof terms measure “expanded logical objects.” A highly compressed instruction is equivalent to handing a complex construction to the engine to generate on the fly; the generated result does not land in the source, but it enters the verification data in full.

    Three practical conclusions follow:

    1. When evaluating compression gains, you must state the unit of measurement: source lines, exported data size, verification time, and peak memory. None of the four can substitute for another.
    2. Whether base library content is counted must be stated explicitly; otherwise cross-version comparisons are meaningless.
    3. Pursuing extremely short source and pursuing minimal verification cost may be optimization goals in opposite directions.

    4. A Practical Slimming Methodology

    For real formal engineering projects, proceed in the following order, from highest to lowest payoff.

    Step 1: establish a measurement baseline. Continuously record source lines, exported proof term size, verification time, and peak memory to form a regression-friendly metrics dashboard, optionally using general-purpose logging services and monitoring and alerting capabilities to observe trends.

    Step 2: push dependencies down and reuse them. Consolidate common lemmas into a shared base library, pinned with a unified version, and avoid each module keeping its own copy. Reuse yields the highest compression ratio.

    Step 3: fold repeated wrappers. Replace batches of thin wrappers with type classes, unified interfaces, or macro-style abstractions, turning “many lines saying the same thing” into “one line meaning many things.”

    Step 4: replace scaffolding with automation. Use stronger automation strategies in place of manual intermediate-step hints, returning derivable detail to the engine, while keeping a few key hints to control search explosion.

    Step 5: verify in layers. Split the proof into a core layer and a support layer: the core stays small and stable, the support layer can be cached and reused, and build artifacts and intermediate results go into object storage services to reduce repeated computation.

    Step 6: keep a maintainability budget. Researchers maintaining a proof must leave some seemingly redundant lines: names, comments, structural layering, explicit intermediate quantities. These lines are insurance against future library upgrades and semantic drift and should not be removed as water.

    5. A Reusable Decision Framework

    When asked “how small can it finally get,” replace a single number with four questions:

    • Are you measuring source or expanded proof terms?
    • Are the base library and cached artifacts counted?
    • Is the scope all theorems or a few specified core results?
    • Who maintains it, over what cycle, and at what acceptable review cost?

    Fix the answers to these four questions, and the compression target turns from a slogan into an acceptance-ready engineering metric. Based on currently public information, the compact version has reached the tens-of-thousands-of-lines scale, but there is no reliable number for the “limit,” and any claim of a precise lower bound should be treated as unverified.

    6. Conclusion

    The value of this global relay lies not in breaking a line-count record, but in turning “volume governance for formal proofs” into a measurable engineering practice. The lesson for developers is general: define the metric first, then optimize; reuse and push down first, then trim by hand; and explicitly reserve a budget between compression and maintainability. If a team runs the build and verification pipeline on general-purpose capabilities such as the container platform, object storage, and monitoring and alerting offered by Baidu AI Cloud, it can turn this method into a sustainable engineering standard rather than a one-off numbers sprint.