Why Formal Proofs Get Shorter Under Compression

    This article examines why compressing a machine-checked formal proof does not produce a single "final length." It breaks the question into three independent dimensions—machine-checkable source size, maintainable engineering structure, and human-reviewable arguments—and explains why a version with fewer source lines can still export a larger proof term for the checker. It also outlines a decision framework and general cloud practices for reproducible verification pipelines.

    When an automated theorem-proving project generated by AI coding tools is continuously optimized by developers worldwide through “relay compression,” its source drops from roughly tens of millions of lines to hundreds of thousands in two days. A natural question follows: how short can it eventually get? Rather than focusing on any specific tool, this article splits the question into three independent technical dimensions—machine-checkable source size, engineering structure that researchers can maintain, and argument details that mathematicians can read and review—and connects them to a counterintuitive observation from public verification: the version with fewer source lines actually hands a larger payload to the checker. Understanding these three layers is a prerequisite for assessing the cost and trustworthiness of any formalization project.

    First, split “how big is the proof” into three questions

    In everyday discussion, “how big is the proof” is a heavily compressed, colloquial question that mixes at least three different measurement targets.

    The first is machine-checkable source size. A formal proof must be written in the language of an interactive theorem prover, where the kernel checks step by step whether each inference is legal. The size of this source depends on the writing style: whether every intermediate conclusion is stated explicitly, or left to an automated tactic to search for.

    The second is maintainable engineering structure. A proof that only one person can understand, and that collapses across the board after a single line is changed, is unacceptable in engineering terms. Maintainability requires clear module boundaries, semantically meaningful lemma names, and repeated patterns abstracted into reusable components. All of these “consume lines,” but they are necessary costs.

    The third is human-reviewable arguments. What mathematicians need to judge is whether the approach holds, whether key lemmas are credible, and whether there are hidden circular dependencies. This layer needs not code lines but narrative, diagrams, discussion of edge cases, and explanations of citations to existing results.

    Conflating the three leads to conclusions like “compressed by 99 percent” that are both inaccurate and irreproducible. A more reasonable statement is: a given version was reduced to a certain order of magnitude under a specific verification workflow, while the other two dimensions did not shrink proportionally.

    Why line counts can be cut by two orders of magnitude

    The original version contains about 175,000 files and about 17 million lines; a subsequent compact version has about 76,000 lines, and a readable version about 300,000 lines. Both shortened versions target only the five target theorems listed in the original. This order-of-magnitude difference does not come from removing mathematical content, but mainly from engineering-level redundancy.

    • Import and dependency bloat: Formalization projects usually depend on a large foundational math library, and auto-generated import lists, wrapper modules, and compatibility layers quickly pile up lines.
    • Auto-generated helper lemmas: To let search tactics find intermediate steps, tools mass-produce many “scaffolding” lemmas that are necessary for the final result but highly repetitive in form.
    • Tactic tuning and retry traces: Multiple equivalent formulations left from debugging, commented-out attempts, and expanded versions written to work around performance bottlenecks all accumulate in the source.
    • Missing reuse abstractions: Writing the same pattern once in each of several sections is the most common source of volume. After extraction into parameterized lemmas or typeclass instances, line counts often drop by an order of magnitude.

    It is worth emphasizing that these compression techniques have a clear boundary of benefit. Once redundancy is fully removed, the remaining lines are determined by the intrinsic complexity of the mathematics, and further compression comes at the cost of readability and maintainability.

    The counterintuitive part: shorter source, larger checker data

    A public independent verification produced a comparison worth remembering: the compact version exported about 5.17 GB of proof data, while the readable version exported about 4.49 GB. The set with fewer source lines hands a larger payload to the checker.

    The reason is that source code and proof terms are not the same thing. What the checker actually verifies is the proof term obtained after the source is elaborated—the complete derivation record at the kernel level. A very short command in the source can drive the proof system to generate thousands or millions of derivation steps:

    1. Source layer: by <automated tactic> <target lemma>
    2. Elaborated: proof_term = thousands to millions of kernel-checkable steps

    So “line count” is a metric about how things are written, while “proof term size” is a metric about derivation complexity. Trading source brevity for automated tactics usually shifts complexity to the elaborated layer; explicit writing does the opposite. When assessing resource consumption, look at source size, elaborated data volume, peak memory, and verification time together, rather than lines alone.

    A trade-off framework for the three lengths

    For real projects, the following framework can guide decisions:

    1. Fix the acceptance criteria first. If the goal is passing machine verification, optimize for smaller elaboration and shorter verification time; if the goal is peer review, optimize for complete narrative and clear structure.
    2. Treat maintainability as a hard constraint. Naming conventions, module partitioning, and one-way dependency direction will not make a proof “shorter,” but they determine whether anyone still dares to change it six months later.
    3. Set a budget for automated tactics. The stronger the tactic, the shorter the source and the larger the elaboration. Teams need to cap verification compute to avoid unpredictable resource spikes on shared environments.
    4. Keep traceable intermediate conclusions. Key lemmas should have independent statements and independent verification paths, making problems easier to locate and results easier for others to reuse.

    Practical engineering recommendations

    Hosting these long-running, compute-intensive formalization tasks in the cloud typically requires several general capabilities working together: using a container platform to pin toolchain versions so verification results are reproducible; using object storage to keep source snapshots and exported proof data for version comparison; using a message queue to split batch verification tasks and control concurrency; and using logging and monitoring with alerts to track memory and runtime anomalies. The general cloud product categories offered by Baidu AI Cloud in such scenarios can serve as a reference foundation for building a reproducible verification pipeline.

    The conclusion is straightforward: there is no single answer to the “final length” of such proofs, only a layered answer. Source can be compressed to the hundreds-of-thousands-of-lines range or lower, but maintainable structure and human-reviewable arguments will not shrink proportionally; and what truly drives the compute bill is the size of the elaborated proof term. Measuring the three dimensions separately and setting constraints for each is the correct way to evaluate formalization engineering.