Formal Proof Compression: Scale, Readability, and Engineering Methods

    Compressing large, AI-generated formal proofs requires more than reducing line counts. This article outlines an engineering approach built around fixed theorem statements, explicit dependencies, parameterized lemmas, proof-term simplification, and human-readable indexes. It also provides a collaborative workflow and release checklist for preserving logical strength while making proofs smaller and easier to review.

    Large formal proofs generated in bulk by AI coding tools often reach a familiar state: the checker accepts them, but humans can barely read them. Line counts may fall by an order of magnitude in a short time, yet compression is not a mathematical result. It is an engineering refactoring of a proof artifact.

    The task should therefore be treated as reproducible software engineering: fix the semantics and dependency boundaries before deleting lines, and preserve reviewability before pursuing a shorter natural-language account.

    1. Separate Correctness, Checkability, and Readability

    Correctness asks whether the mathematical proposition holds. It depends on the axioms, accepted theorems, and absence of gaps in each inference.

    Checkability asks whether a machine can derive the goal from the declarations within the agreed formal system, without introducing undeclared assumptions.

    Readability asks whether a person with the necessary background can locate the key lemmas, verify external references, and identify hidden conditions within a reasonable amount of time.

    These properties are often collapsed into a single metric. Fewer lines mean less text, not necessarily fewer gaps or a more understandable proof.

    A common failure mode is to fold repeated arguments into enormous automated tactics. A proof may shrink from hundreds of thousands of lines to tens of thousands while hiding branch conditions, prerequisites of classical results, and assumptions valid only inside the development within proof terms that are difficult to review. Checking may still succeed, but reviewers lose a usable entry point.

    Every compression plan should therefore begin with explicit acceptance criteria:

    • Preserve the theorem statement and the scope of its quantifiers, especially whether the result is unconditional or depends on specified results from analytic number theory.
    • Either formalize external theorems within the same trusted base or declare their premises through explicit interfaces. “It is in the literature” is not a dependency declaration.
    • Use automation to eliminate mechanical steps, not to change logical strength.
    • Retain a human-readable index connecting the top-level theorem to the key estimates.

    2. Why Formal Proofs Become So Large

    AI coding tools are effective at local completion. Given a lemma goal, they unfold definitions, invoke existing tactics, and copy similar proofs. Without a global architecture, each special case may receive its own argument, producing repeated estimates, repeated exchanges of summation order, and repeated analytic continuation steps.

    Patch-driven cycles of generation, failure, and regeneration add another layer of waste: dead code, unnecessarily strong assumptions, and temporary lemmas introduced solely to make a particular check pass.

    A second source of growth is a mismatch in granularity. If a formal development places every inequality on a separate line and explicitly unfolds every substitution, its line count starts to reflect the size of the proof term’s syntax tree rather than the number of mathematical ideas.

    A human proof may say “by the standard convexity estimate.” If the machine inlines that estimate hundreds of times, the development expands dramatically. Compression lifts those repeated arguments back into named lemmas, leaving only parameters and premises at each call site.

    It is also important to distinguish two kinds of brevity:

    • Formal brevity: Smaller source text or proof terms processed by the checker.
    • Expository brevity: Fewer human-facing sections, dependency diagrams, and key estimates.

    A one-line call to an external library followed by “proof complete” is not successful compression if the library has not been reviewed or its interface does not match the required statement. It merely moves the bulk somewhere less visible.

    3. A Technical Approach to Compression

    3.1 Establish Dependency Layers

    Divide the development into four layers and avoid arbitrary inlining across their boundaries.

    1. Foundation layer: Stable definitions and lemmas for fields, series, integrals, and complex analysis.
    2. Interface layer: External theorems actually used by the development, with explicit assumptions, conclusions, and domains of applicability.
    3. Core layer: Estimates, identities, and principal lemmas specific to this proof.
    4. Assembly layer: Short scripts combining the core lemmas into the final proposition.

    Prioritize compression in the assembly layer and duplicated parts of the core layer, rather than trying to shorten the foundations first. Stable foundations make higher-level reuse easier.

    Measure source line counts, proof-term node counts, and cross-file reference depth together. Optimizing only one easily manipulated count can obscure the real cost.

    3.2 Merge and Parameterize Lemmas

    Compare structurally similar proofs. When goals have the same shape and differ only in constants or summation ranges, replace them with a parameterized lemma.

    Before merging, check whether the premises have silently become stronger. Changing a statement from “in a certain half-plane” to “for all complex numbers” may reduce text while making the statement false.

    A merged lemma should include a minimal counterexample or a boundary note explaining why its parameter constraints cannot be relaxed further.

    A review record can remain neutral and actionable:

    1. lemma_id: estimate.convex.uniform
    2. premises: [region=half_plane, growth=poly, no_extra_zero_assumption]
    3. replaces: [file_a:lemma_12, file_b:lemma_07, file_c:lemma_19]
    4. check: machine_accepted
    5. human_note: Constant C depends only on the weight, not on the expansion point

    This record is not itself a proof, but it helps prevent premises from disappearing when files are removed.

    3.3 Simplify Proof Terms, Not Just Source Formatting

    The largest artifacts are often proof terms: long sequences of equivalent transformations, repeated rewrites, and expansions that a single induction could capture.

    Useful engineering techniques include:

    • Extract shared subproofs so multiple locations reference the same proof object rather than duplicate it.
    • Replace character-by-character expansions with abstract steps in equality chains, while keeping each step independently checkable.
    • Bound the search depth and timeout of large tactics to prevent them from generating enormous, unreadable proof terms internally.
    • Remove dead generated code. Declarations outside the transitive dependency closure of the top-level theorem should normally be moved out of the main development rather than retained to inflate repository size.

    After simplification, run a complete recheck with the same checker. Compare the sets of axioms and external interfaces before and after compression. If either set has grown, the refactoring has introduced new assumptions and must be rolled back.

    3.4 Provide a Natural-Language Companion, Not a Substitute Proof

    Human-facing compression should produce three cross-referenced documents, rather than replace checking with a shorter story:

    • Statement and roadmap: The top-level proposition, logical stages, and points where classical results are used.
    • Key-estimate handbook: The inputs and outputs of each core inequality, along with the symptoms of failure when its conditions are not met.
    • Formal correspondence map: The formal declaration supporting each natural-language assertion. Mark gaps as “not formalized,” not “obvious.”

    If a shorter document also contains fewer references, check whether a conditional proof has been presented as unconditional. Literature references explain interfaces; they do not replace formal dependencies.

    A version that explicitly contains unresolved internal assumptions should be labeled a “conditional reconstruction” or “working draft” in its title and abstract. It should not be presented as a fully checked proof.

    4. Collaboration: Relay Refactoring Without Scope Inflation

    Global or cross-team collaboration can work well for proof compression, but it needs review gates rather than momentum-driven edits. A fixed workflow helps.

    1. Freeze the proposition and interfaces. Do not accept large-scale deletions or rewrites before this boundary is settled.
    2. Measure the baseline. Record line counts, proof-term size, checking time, external interfaces, and unresolved assumptions.
    3. Refactor in small batches. Handle one dependency cluster per change. Explain which duplication was removed and whether any premises changed.
    4. Use two-person review. One reviewer examines checker-level differences; another checks whether mathematical premises have been strengthened or moved elsewhere.
    5. Sample readability. Randomly select assembly-layer calls and ask reviewers to explain why each step holds without consulting generation logs.
    6. Label versions clearly. Retain both a compact, checkable version and a readable index version. Do not publish only one while claiming to provide both.

    AI coding tools are useful for proposing merge candidates and filling in mechanical steps. They should not independently decide that an external theorem can be removed. Human reviewers are responsible for protecting interfaces and logical strength.

    For cloud-based collaboration, object storage can hold baselines and proof-term snapshots. Code review and continuous checking can block regressions, while monitoring and alerts can flag sudden changes in checking time or dependency counts. These are general engineering capabilities, not substitutes for mathematical judgment.

    5. How Small Can a Proof Become?

    Compression has real lower bounds.

    • An external theorem that has not been formalized cannot simply be compressed away. It must remain at an interface, and that interface has a minimum statement cost.
    • Mathematically independent core estimates cannot be collapsed into a content-free lemma with no parameters.
    • The length of a readable index grows roughly with the number of critical logical branch points, rather than linearly with the original line count. These include changes of method, applications of zero-density results, and treatment of exceptional sets—steps that determine logical strength.
    • Checking time and source line count are not the same function. Excessive inlining may produce shorter text but larger proof terms and slower checking; excessive splitting may have the opposite effect. Checking time must be part of the budget.

    In practice, the first compression pass mainly removes copy-and-paste duplication and can yield large reductions. The second focuses on parameterization and shared subproofs, usually delivering smaller reductions but higher quality.

    A third pass that still aims to “cut another half” often risks hiding premises. At that point, stop treating line count as the primary target. Instead, reduce unlabeled assumptions and shorten the path from the top-level theorem to the core estimates.

    A healthy endpoint is not the theoretical minimum number of lines. It is a development that satisfies all of the following:

    • The complete proof passes machine checking.
    • External interfaces are fully accounted for or explicitly listed.
    • Humans can review the critical path within a reasonable amount of text.
    • Compression changes remain traceable.

    When someone presents an exceptionally short proof artifact, the review questions should be “Where are the dependencies?” and “Are the premises still visible?”—not merely “Is the number smaller?”

    6. Pre-Release Review Checklist

    Before publication, verify at least the following:

    • Compare the top-level proposition’s quantifiers, domain, and conditions word for word against the frozen version.
    • Confirm that external interfaces have not silently increased. Each must be traceable to a formal declaration or an explicit unfinished item.
    • Ensure that no “key lemma” is merely claimed in comments while remaining outside the dependency closure.
    • Check that automation failures were addressed through explicit premises, not concealed by stronger assumptions.
    • Make every step in the readable index point back to a formal declaration. Remove statements that cannot be mapped, or label them as motivation rather than proof.
    • Preserve the pre-compression baseline so readers can inspect whether a particular deletion changed logical strength.

    7. Conclusion

    Reducing machine-generated proofs from millions of lines to a more compact formal development is a problem of dependency management, proof-term sharing, and frozen interfaces—not promotional framing.

    Line count is a lagging indicator. Checkability and the visibility of premises are the constraints that matter. Every compression round should answer the same question: did it remove duplication, or did it move assumptions into an invisible library?

    Smaller is better only when the assumption set does not expand and humans can still review the critical path. Until a readable version is stable, the size of the formal text should not be treated as evidence that the mathematical result has been fully established.