Code Compression in Automated Theorem Proving: A Practical Engineering Guide
This article examines how formal proofs in automated theorem proving can balloon to hundreds of thousands of lines, and how a relay-style compression workflow reduced more than two million lines in two days. It covers the root causes of proof bloat, a four-stage division of labor, the trade-off between compression and readability, the limits of extreme compression, and a repeatable slimming process with regression monitoring.
1. Why Formal Proofs Balloon to Hundreds of Thousands of Lines
When a team fully formalizes a class of deep mathematical statements—for example, assertions equivalent to a well-known conjecture in number theory—the result is often counterintuitive: the proof script runs to hundreds of thousands of lines, far beyond expectations. The causes are not mysterious:
- Explicit expansion of low-level dependencies: Formal systems require every inference step to be justified, so lemmas that look “obvious” on paper must be expanded layer by layer.
- Redundant output from automation tactics: Proof terms produced by automated search often contain many repeated branches and intermediate conclusions.
- Accumulation across multiple people and rounds: Different contributors fill gaps in their own style, so duplicate lemmas and similar fragments keep piling up.
2. Relay-Style Compression: Cutting Over Two Million Lines in Two Days
One practice worth borrowing is “relay compression”: different contributors take over the same proof in sequence over a short period, each leg focusing on only one class of redundancy. In two days, more than two million lines were removed, shrinking the proof to roughly fifty thousand lines. The key is clear division of labor, clean boundaries, and independently verifiable legs.
- Leg one: remove duplicate lemmas and build a shared lemma library.
- Leg two: merge isomorphic branches, replacing copy-paste with parameterized lemmas.
- Leg three: replace manual expansion with automated tactic calls.
- Leg four: delete unreachable code and leftover temporary assertions from history.
3. The Counterintuitive Relationship Between Compression and Readability
A pattern that keeps recurring in practice: the fifty-thousand-line and seventy-thousand-line versions are actually harder to read than the three-hundred-thousand-line version. Compression usually comes at the cost of introducing more abstract bridging lemmas, so readers must hold two contexts in mind at once—the abstraction layer and the expansion layer. Engineering recommendations:
- Generate layered navigation documentation for the compressed script, annotating the responsibility of each layer.
- Keep both a “readable version” and a “slimmed version,” cross-checked by the same verifier.
- Add intent comments to key bridging lemmas, explaining which original fragments they replace.
A schematic layered organization looks like this:
layer_0_axioms # Base axioms and definitionslayer_1_bridge # Abstract bridging lemmas (compression artifacts)layer_2_automation # Automated tactic wrapperslayer_3_entry # Top-level goals
4. The Boundary of Extreme Compression: The Truth About One-Line Proofs
The “one-line version” circulating online is essentially a delegation of the full proof to an external library or external service; the single line is only a call entry point. It reveals an important boundary: what gets compressed is the expression, not the trustworthiness. If verification responsibility is moved outside, the size can approach zero, but the audit chain moves with it. Workable compromises:
- Explicitly record the version and checksum of external dependencies.
- Add a pinned-version re-verification step to continuous integration.
- Maintain an admission list for external dependencies along with a rollback plan.
5. A Practical Slimming Workflow
- Baseline freeze: Get the full version to pass verification first, and record the line count and runtime baseline.
- Redundancy clustering: Find repeated subgraphs using the lemma dependency graph.
- Abstraction replacement: Replace isomorphic fragments with parameterized lemmas while keeping the number of abstraction layers under control.
- Automation recovery: Hand mechanical steps to tactics to reduce manual expansion.
- Dual-version verification: Run both the slimmed version and the readable version through the verifier.
- Regression monitoring: Bring line count, verification time, and failure rate into monitoring, alerting, and logging services.
6. Engineering Benefits and Risk Control
Compression directly reduces verification time, narrows the maintenance surface, and cuts collaboration conflicts. The risks concentrate in the comprehension cost of overly deep abstraction layers and the trust cost of introducing external dependencies. If general-purpose cloud capabilities carry the workflow, container platforms can run verification tasks, object storage can hold versioned artifacts, message queues can decouple relay tasks, and monitoring and alerting can track regression metrics—turning “relay compression” into a repeatable, auditable day-to-day engineering practice.
