From Millions of Lines to 50K: A Practice in Compressing AI-Generated Proofs

    Recently, an AI-generated formal proof of the generalized Riemann hypothesis underwent a collaborative compression process, shrinking from over 17 million lines to roughly 52,000 lines. This article explores the causes of AI-generated code bloat, outlines a four-layer compression methodology ranging from syntax to representation, and highlights the inherent trade-offs between length, readability, and verifiability. It further translates these proof compression practices into actionable governance strategies for managing AI-generated code in software engineering.

    I. Event Review: A Two-Day “Slimming Relay”

    Recently, an AI-generated formal proof of the generalized Riemann hypothesis triggered a roughly two-day collaborative compression effort within a public community. According to public information, the initial version exceeded 17 million lines. Through parallel task division among multiple participants, subsequent versions shrank to around 300,000 lines and 76,000 lines, eventually converging to an “ultra-compact” version of about 52,000 lines (53,691 lines). A public repository emerged on the code hosting platform, and participants even created visualizations of the shrinkage from millions down to 300,000 lines.

    Notably, this process was not a “solo refactor” but rather resembled parallel relay + cross-review in software engineering. Different participants took charge of lemmas and proof fragments across various chapters, and the compressed results were merged back into the main branch. This organizational pattern is highly analogous to large-scale refactoring in commercial software and forms the core methodology this article aims to abstract.

    Simultaneously, several “informal” artifacts appeared: a 322-page natural language proof (including 43 pages in English, 38 pages in Chinese, and a 56-page formal correspondence document, citing 47 papers); a 265-page working draft; and a 117-page “conditional refactoring” (which retained internal assumptions without conventional proofs, left some external theorems without literature cross-referencing, and was explicitly not claimed as a complete proof by the author). Some users jokingly provided a “one-line version” by directly calling an external library that encapsulates the entire proof. These artifacts collectively demonstrate that compression is not a single-objective task, but a trade-off among multiple goals: length, readability, and credibility.

    II. Why AI-Generated Proofs Bloat to Millions of Lines

    To understand why the compression space was so massive, we must first understand the causes of the bloat. It is not as simple as the model being “verbose”; rather, it is the cumulative effect of four factors:

    1. Proof assistant kernels are “zero-trust.” The kernel of an interactive theorem proving system only accepts fully expanded terms, and every step of inference must provide a verifiable intermediate object. Human proofs rely on omissions like “obviously” or “similarly,” but formal systems do not accept omissions—gaps must be filled by automation tactics or proven lemmas.
    2. Generative models have an “expansion” writing habit. Models tend to write every step as an explicit term construction, lacking the intention for abstraction and reuse. This leads to the same patterns being repeatedly rewritten at the scale of millions of lines.
    3. Term-level expansion in the absence of automation tactics. When suitable decision procedures or simplification tactics are unavailable, the proof degrades into a step-by-step teardown of the target term, causing the line count to grow combinatorially with the problem size.
    4. Lack of engineering practices. Without version control, lemma libraries, naming conventions, and review processes, duplicate lemmas and dead code accumulate massively.

    These four points explain a counterintuitive phenomenon: the volume of bloat is primarily driven by “representation redundancy” rather than “logical complexity.” This is why the compression space could span three orders of magnitude.

    III. Four-Layer Compression Methodology: From Syntax to Representation

    The reusable compression path can be abstracted into four layers, with increasing returns and increasing risks at each level.

    Layer 1: Syntax Layer (Equivalence Rewriting and Dead Code Elimination). Delete never-referenced lemmas, merge duplicate fragments, and replace inlined massive terms with named lemmas. This layer does not alter the proof structure, carries the lowest risk, and is typically handled in bulk by automation tools.

    Layer 2: Structural Layer (Lemma Extraction and Abstraction). Identify recurring proof patterns and extract them into parameterized lemmas, rewriting “special case proofs” into “general theorem + instantiation.” This layer is the primary source of line reduction, but it requires human judgment regarding the boundaries of abstraction; over-abstraction can harm readability.

    Layer 3: Tactic Layer (Replacing Expansion with Automation). Replace step-by-step expansion with simplification tactics, decision procedures, or established lemma libraries. Illustrative pseudocode is as follows (expressing the concept, not specific system syntax):

    1. # Before compression: explicit step-by-step expansion (illustrative)
    2. Lemma target : A -> B
    3. Proof
    4. have h1 : A -> C := by intro a; exact step1 a
    5. have h2 : C -> D := by intro c; exact step2 c
    6. have h3 : D -> B := by intro d; exact step3 d
    7. intro a; exact h3 (h2 (h1 a))
    8. # After compression: extracted lemma + automated tactic (illustrative)
    9. Lemma step_CD : C -> D := by auto
    10. Lemma target : A -> B := by intro a; auto [step1, step_CD, step3]

    Layer 4: Representation Layer (Translation between Formal and Natural Language). The same proof can be projected into different representations: formal code is machine-verifiable but poorly readable, while natural language is readable but not machine-verifiable. The two serve as an exchange between “verifiability” and “understandability.”

    IV. Core Tension: 50K Lines Are Not Necessarily More Readable Than 300K

    This is the conclusion from this event that the engineering community should heed the most: the readability of the 52,000-line and 76,000-line versions is actually worse than that of the 300,000-line version. The reason is that compression alters information density and abstraction levels:

    • Individual lemmas carry more inference steps, requiring readers to hold more context at once.
    • The invocation of automation tactics is “black-box”; readers cannot deduce what the tactic did just by looking at the code.
    • Extreme compression is often accompanied by shortened naming, resulting in the loss of semantic clues.

    Therefore, we recommend introducing the concept of a “readability budget“: treat line count as a cost metric and the “average cognitive load per definition/lemma” as a quality metric, constraining both simultaneously. An operable engineering compromise is layered delivery: maintain a medium-granularity main branch (e.g., hundreds of thousands of lines) for human review, alongside an ultra-compact version for machine verification and rapid iteration. Both are guaranteed to be equivalent by the same build process.

    V. Credibility: Compression Must Not Relax Verification

    Compression is a “representation transformation,” not a “proof relaxation.” The chain of credibility should contain at least four links:

    1. Kernel Verification: The final product must pass the independent check of the proof system’s kernel, not just the interactive state during generation.
    2. Equivalence Explanation: Each layer of compression must provide a reviewable transformation rationale (reference/replacement/abstraction), forming a change list.
    3. Assumption Auditing: Explicitly list external theorems, unproven lemmas, and internal assumptions. The aforementioned 117-page “conditional refactoring” is a typical sample of this missing link; it has value but cannot be treated as a complete proof.
    4. Reproducible Build: Pin the toolchain versions, dependencies, and build scripts so that third parties can rebuild and review with one click.

    A mathematics researcher who closely follows this field publicly stated that page count itself is not the point; readability is key. They estimated that, assuming the proof is correct, a barely human-readable version would appear within a month—aligning with the direction of “layered delivery.”

    VI. Implications for Software Engineering: Governing AI-Generated Code Bloat

    Translating the above experience into daily R&D yields an actionable checklist:

    • Metric-First: Track line count, duplication rate, lemma (function) reuse rate, and cyclomatic complexity for AI-generated code simultaneously, rather than only looking at “generation speed.”
    • Shift-Left Gatekeeping: Integrate dead code detection, duplicate fragment detection, and coverage gating into Continuous Integration (CI). Intercepting bloat before merging is the least costly approach.
    • Abstraction Reviews: Make “whether this should be extracted into a common function/lemma” a standard checklist item in code reviews.
    • Collaboration Infrastructure: Large-scale parallel refactoring requires unified code hosting and review pipelines, object storage for build artifacts, container platforms for reproducible build environments, and logging services with monitoring and alerting to track build duration and failure rates before and after compression. These capabilities are available as general categories on cloud platforms like Baidu AI Cloud and can be combined as needed.
    • Dual-Version Strategy: Maintain a machine-readable compact version and a human-readable layered version in parallel, ensuring consistency through automated workflows.

    VII. Conclusion: How Small Can It Be Compressed?

    The two-order-of-magnitude shrinkage from over 17 million lines to about 52,000 lines in two days illustrates that the initial volume of AI-generated content primarily reflects the redundancy of the generation strategy, not the inherent complexity of the problem. The true lower bound is determined by three factors: the information content of the problem itself, the thickness of the reusable lemma library, and the coverage of automation tactics. Therefore, there is no single answer to “how small can it be compressed,” but it is certain that the end goal of compression is not absolute brevity, but the feasible intersection of three objectives: “machine-verifiable + human-reviewable + fully disclosed assumptions.”