Compression and Readability of Large-Scale Formal Proofs
Large-scale formal proofs often suffer from severe bloat when generated by AI or automated tools, expanding to sizes that are difficult for humans to review. This article abstracts the compression of these proofs into a reusable engineering problem, exploring where volume originates, what constitutes legitimate compression, and the inherent trade-offs with readability. It provides a structured workflow for organizing relay compression, acceptance metrics, and practical convergence criteria to help teams manage massive formal proofs effectively without sacrificing long-term maintainability.
Large-scale formal proofs are not simply “pasting natural language arguments into an editor.” They require every inference step to be checked by a proof kernel: definitions must have types, lemmas must be referenced, and tactics must successfully close the current goal. Intelligent programming tools excel at rapidly spreading out this text but do not inherently care about repetition, naming, or human reading paths. As a result, the proof volume can bloat to an unreviewable scale in a short time. Public discussions have cited an example where a formal proof related to the generalized Riemann hypothesis was reduced by approximately 2.4 million lines in a two-day relay compression effort, then further compressed from about 300,000 lines to roughly 50,000 lines—though some noted that the shorter version was actually harder to read. Below, we abstract this into a reusable engineering problem rather than a tool-specific user experience review.
1. Where Does the Volume Come From?
The line count of formal text is primarily determined by four types of factors.
First, search traces. Automated proofs often try multiple tactics. Failed branches, intermediate assertions, and temporary auxiliary lemmas are preserved to avoid detours during reruns. While largely redundant for the kernel, these act as logs for the generation process.
Second, copying instead of abstracting. If similar estimates, inequalities, and analytic continuation steps are each expanded individually, the line count will grow linearly or even super-linearly with the number of cases. When humans write proofs, they say “similarly.” If a machine is not instructed to extract common lemmas, it will write out “similarly” as another full copy.
Third, granularity out of control. Splitting a goal into hundreds of extremely small sub-goals, each taking a few to dozens of lines, results in a massive total. Conversely, compressing many steps into a single complex tactic reduces line count but makes failure localization nearly impossible.
Fourth, dependency bloat. To avoid writing basic lemmas, proofs often reference huge standard libraries or custom prep libraries. The main file appears short, but its closure is massive. Counting only the main file severely underestimates the true scale and misjudges compression effectiveness.
Therefore, “how many lines were cut” is merely an outcome metric. Before compression, you must first define the counting scope: main development files, generated files, standard library references, the number of proof objects, kernel check time, and whether new axioms are introduced.
2. What Does Compression Actually Change in Proofs?
Compressing a proof is not applying a general text compression algorithm, nor is it simply deleting comments the checker cannot parse. Legitimate compression must satisfy: under the same logical foundation and the same explicit axioms, the re-checking still passes, and the mathematical meaning of the theorem statement is not secretly weakened.
Common, legitimate compression techniques consistent with proof engineering practices include:
- Extracting common lemmas. Write recurring estimates, substitutions, and limit exchanges into clearly named lemmas, leaving only the calls in the main proof. The line count drops due to deduplication, not skipping steps.
- Raising the abstraction level of tactics. Replace dozens of lines of manual rewriting with a single verified automated tactic. However, the tactic itself should be independently testable and provide readable sub-goals upon failure.
- Merging parallel cases. If several cases differ only by parameters or symbols, they should be parameterized rather than copying three nearly identical scripts.
- Cleaning up unreachable proofs. Delete experimental lemmas and failed search logs never depended upon by the final theorem. Before deletion, use dependency analysis to confirm this and avoid mistakenly deleting implicitly referenced definitions.
- Tightening interfaces. Overly broad assumptions force subsequent text to repeatedly perform type conversions and prove side conditions. Writing assumptions accurately can sometimes reduce lines more effectively than writing another automation block.
Illegitimate “compression” includes: using uninterpreted axioms for key steps, marking proofs as opaque objects to skip checks, or altering the theorem statement to make the problem easier. These operations make the line count look good but render the result no longer a proof of the original proposition.
3. Why Shorter Is Often Harder to Read
If a 30,000-line version consists of numerous named lemmas and short proofs, readers can still understand the structure by following the directory. After compressing to around 50,000 lines or fewer, the common trade-off is that information is folded into a few massive tactics or highly parameterized lemmas. The local line count decreases, but the cognitive load increases, typically for three reasons.
First, worse naming. To facilitate merging, lemma parameters increase, and names become generic, like “auxiliary estimate” or “main lemma,” losing their mathematical roles.
Second, invisible proof states. Long tactics rewrite multiple goals at once, leaving no intermediate assertions. When a check fails, the reader cannot see “which inequality got stuck.”
Third, narrative destruction. The original sections often correspond to chapters in a mathematical paper: zeros, functional equations, explicit formulas, error terms. If compression only seeks the shortest dependency graph, it shatters these chapters into fragments arranged by call relationships. The machine can check it easily, but humans cannot easily cross-reference the original arguments.
Therefore, readability cannot be replaced by line count. More useful signals are: whether key theorems can show assumptions and conclusions within one screen, whether each file corresponds to a mathematical theme, whether failures can be localized within dozens of lines, and whether a new contributor can modify a lemma without understanding all the automation.
4. How to Organize Relay Compression
It is more accurate to treat cutting two million lines as a continuous integration task rather than a one-off genius deletion. The executable process is roughly as follows.
Freeze statements first. Write the propositions to be ultimately proven, the allowed axioms, and the base library version into interfaces that cannot be arbitrarily changed. Anyone involved subsequently can only change the proof, not the problem statement.
Build dependency graphs and hotspots. Tally which lemmas are referenced most, which files have the highest duplication rate, and which tactics take the longest time. Compression should target hotspots first, rather than uniformly deleting every line.
Fragment the relay. Each participant takes a module: deduplicating, parameterizing, or rewriting tactics. Submissions must include evidence of passing checks and a comparison showing “statements unchanged.” Modules are handed off via clear lemma boundaries to prevent two people from simultaneously rewriting the same segment and causing semantic drift.
Perform readability write-backs. Once the volume drops to the target range, open a separate refactoring round solely for reading: restore chapter titles, write mathematical comments for core lemmas, and split ultra-long tactics back into small, independently testable tactics. This round allows for a slight rebound in line count. If the 50,000-line version is harder to read than the 300,000-line one, it usually means this round was skipped.
Finalize acceptance. This should at least include: full kernel check passing, an axiom list consistent with the baseline, verbatim comparison of key theorem signatures, acceptable check time and memory, and a human-oriented structural guide. A short proof without a guide merely transfers the reading cost to the next maintainer.
5. A Minimal Structural Example
The following schematic code demonstrates “extracting a lemma” without binding to any specific proof assistant’s syntax. It only illustrates the structure.
-- Target: Prove a class of highly similar estimates only oncelemma bound_shift (a b : Real) (h : 0 < a) :estimate (shift a b) ≤ estimate a + error b := by-- Handle substitutions and errors centrally here for multiple calls...theorem main_statement :critical_strip_claim := byapply reduce_to_estimates· exact bound_shift a1 b1 h1· exact bound_shift a2 b2 h2· exact bound_shift a3 b3 h3
Before compression, the three bound_shift calls might each expand into hundreds of lines of nearly identical scripts. After compression, the line count is concentrated within the lemma, and the main theorem retains its mathematical structure. If bound_shift were further compressed into a black box that cannot be inspected step-by-step, the main file would be shorter, but reviewers would be unable to verify where the error terms come from.
6. Metrics to Watch During Acceptance
Line count is suitable for observing trends but should not be the sole objective. A more robust combination of metrics includes:
- Final theorem statement diff: Should be zero, and assumptions should not be strengthened to the point of changing the problem.
- New axioms added: Should be zero, or each one should have documented mathematical justification and isolation instructions.
- Proof closure size: Includes files actually depended upon, rather than just looking at the main file.
- Check cost: Full check time, peak memory, and whether incremental checking is available.
- Duplication rate: Whether the number of similar proof blocks has decreased.
- Localizability: After artificially breaking a key inequality, does the error point to a smaller range?
- Guide completeness: Can the dependency chain from assumptions to conclusions be explained in a few chapters?
If only line reduction is rewarded, participants will tend to merge files, shorten identifiers, and hide intermediate assertions. These practices can create dramatic line count drops within two days but harm subsequent audits. Listing both “check still passes” and “key path remains explainable” as thresholds gives compression its engineering significance.
7. Similarities and Differences with Regular Code Refactoring
Formal proof refactoring shares dependency analysis, deduplication, and interface stability with business code refactoring, but the failure modes are harder: if a type or tactic is wrong, the entire theorem is unproven, leaving no room for “observing in production.” On the other hand, proof text has almost no runtime business branches; correctness is determined by the kernel. Therefore, you can be bolder with equivalent transformations, as long as both before and after the transformation can be checked.
If teams include long proofs generated by intelligent programming tools in their repositories, they should treat them as generated code requiring continuous refactoring: separate generation from handwriting, prohibit committing search logs to the mainline, limit the scope of automated rewrites with module boundaries, and run full checks before merging. Object storage can save check logs and historical versions, message queues can string together fragmented tasks, container platforms can fix the proof environment, and monitoring alerts can track regressions in check duration. These are general engineering capabilities that cannot replace mathematical lemma design.
8. Where to Set the Target
“How small it can ultimately get” has no answer independent of the proposition’s difficulty. The lower bound is roughly determined by three things: the length of the theorem statement and necessary definitions, the essential mathematical steps that cannot be further merged, and the structural lines retained for human understanding. If you only optimize the first two, the text can continue to shrink until it approaches a machine-executable but human-unwalkable script. Factoring in the third item usually reveals a plateau where the line count is slightly higher but the maintenance cost is lower.
For propositions at the scale of the generalized Riemann hypothesis, reducing from millions of lines to around 100,000 primarily digests duplication and search garbage. Dropping another order of magnitude from 100,000 lines begins to consume the structure prepared for humans. The “shorter but harder to read” phenomenon in public discussions aligns with this transition, rather than a sudden failure of compression technology.
A practical convergence standard can be written as: statements frozen, checks passing, no new axioms, hotspot duplication eliminated, and core chapters still explainable against the mathematical arguments. Continuing to cut lines beyond this point should require separate justification that the benefits outweigh the readability loss, rather than treating the minimum line count as proof quality itself.
