Compressing and Collaborating on Large-Scale Formal Proofs

    This article examines how a formal proof of the Generalized Riemann Hypothesis was compressed from over 17 million lines to roughly 300,000, then down to 76,000 and 52,000 lines, cutting more than 2.4 million lines in two days. It explains why initial automated generation balloons to millions of lines, outlines five layers of compression from syntax to representation, and discusses the trade-offs between compression, readability, and trustworthiness. It also covers engineering practices for relay-style collaboration, including task partitioning, a unified baseline, incremental verification, metrics dashboards, and version snapshots, plus the role of natural-language proof drafts. The key takeaway is that further compression depends on abstraction quality and disciplined collaboration rather than tooling capacity.

    1. The Signal: Cutting 2.4 Million Lines in Two Days

    A formal proof of the Generalized Riemann Hypothesis was compressed from more than 17 million lines to about 300,000 lines, then further reduced to 76,000 and 52,000 lines. In total, more than 2.4 million lines were removed in two days. This is not simply “deleting code.” It is the inevitable outcome of proof engineering entering a phase of large-scale collaboration. Early versions were generated in bulk by automated tools and were full of duplicate lemmas, redundant intermediate steps, and low-value boilerplate. As more contributors reused existing results, merged isomorphic branches, and abstracted repeated reasoning into reusable lemmas, the line count dropped in stages.

    It is important to note that line count is not the only metric. The compressed version is shorter, but it has a higher level of abstraction and more frequent jumps, so the reading burden on humans may actually increase. Therefore, when discussing “how small it can ultimately get,” we must also discuss readability, maintainability, and trustworthiness.

    2. The Root of Bloat: Why the First Generation Reached Tens of Millions of Lines

    • Proof state space explosion: Formal systems require every step to have an explicit justification, and automated strategies tend to expand automatically solvable goals into large numbers of basic steps.
    • Lack of global reuse: When generated in batches, the batches are unaware of each other, and the same lemma is proved repeatedly.
    • Type and structural redundancy: Intermediate types, wrapper layers, and conversion functions introduced to pass the checker accumulate layer upon layer.
    • Tactic script bloat: Unconstrained combinations of automation tactics produce lengthy and hard-to-maintain scripts.

    3. Five Layers of Compression

    1. Syntax layer: Delete useless lines, merge blank lines, and standardize naming. The gains are limited but the risk is zero.
    2. Lemma layer: Identify recurring intermediate conclusions and extract them as standalone lemmas. This yields the largest gains.
    3. Structure layer: Fold isomorphic branches into parameterized theorems, using one proof to cover a family of goals.
    4. Tactic layer: Replace lengthy scripts with shorter high-level tactics to reduce state expansion.
    5. Representation layer: Change data representations and abstract interfaces so that subsequent proofs become shorter overall.

    The illustrative abstraction process can be understood as follows:

    1. # Before compression: the same pattern is expanded repeatedly in multiple places
    2. lemma step_a : P x -> Q x := by intro h; unfold P at h; ...
    3. lemma step_b : P y -> Q y := by intro h; unfold P at h; ...
    4. # After compression: extract a unified lemma and parameterize it
    5. lemma step_general {z : α} (h : P z) : Q z := by
    6. unfold P at h
    7. exact core_argument h

    4. The Trade-off Between Readability and Trustworthiness

    Compression increases abstraction density, and readers need to maintain a larger “context stack.” Engineering practice suggests three parallel strategies. First, keep an uncompressed or lightly compressed reference version for comparison. Second, generate navigation documentation for each abstraction layer, annotating lemma dependencies and entry theorems. Third, use automated checks to ensure semantic consistency before and after compression, for example by comparing the type signatures of core theorems one by one and performing regression validation on key lemmas.

    A drop in line count does not mean a drop in risk. Every abstraction introduces new implicit premises, and without a dependency graph and change records, subsequent maintenance costs will quickly outweigh the benefits.

    5. Engineering Methods for Relay-Style Collaboration

    Multiple people compressing continuously in a short time is essentially a distributed refactoring effort. Practical approaches include:

    • Task partitioning: Divide non-conflicting work packages according to the lemma dependency graph to avoid frequent conflicts in the same file.
    • Unified baseline: Agree on a fixed base version and naming conventions, and submit all compression based on the same baseline.
    • Incremental verification: Run the full check on every commit, roll back on failure, and prohibit “merge first, fix later.”
    • Metrics dashboard: Track four types of metrics: line count, lemma count, maximum dependency depth, and check duration, and use monitoring alerts to catch abnormal fluctuations.
    • Version traceability: Keep snapshots before and after compression, and use a logging service to record the rationale for decisions for easy traceback.

    On the infrastructure side, a container platform can be used to lock down a reproducible build environment, object storage can hold snapshots from each stage, and a message queue can serialize commits and validation to avoid baseline drift caused by concurrent work by multiple people.

    6. The Value of the Natural-Language Version

    In addition to the formal code, there are hundreds of pages of natural-language proof drafts, along with shorter language-specific versions paired with formal correspondence documents, citing dozens of existing works. The natural-language version serves an “explainability” role: it lets readers first build an overall intuition for the argument before entering the formal details. The two forms validate each other and can significantly reduce the overall cost of understanding.

    7. Conclusion: The Endpoint of Compression Is Determined by Abstraction Quality

    From tens of millions of lines to around 50,000 lines, the compression space comes mainly from reuse and abstraction, not deletion. The bottleneck for further compression is no longer tool capacity, but the quality of abstraction design and the rigor of the collaboration process. The lesson for engineering teams is clear: treat the proof or code base as a long-term asset, and use dependency graphs, baseline constraints, and automated validation to turn “relay compression” into a sustainable daily practice rather than a one-time sprint.