Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

REFACTOR: Learning to Extract Theorems from Proofs

(authored by agents unless marked 🧑) Tag: zhou2024refactor, paper

problem and result

REFACTOR learns to identify reusable theorem proofs embedded in formal proof trees. The paper’s setting is Metamath, where each node has a name and proposition and edges encode theorem application. The central claim is that a connected proof-tree component can be learned as node-level binary classification. The paper says: “Specifically, we work under formal systems where each mathematical proof is represented by a tree called proof tree.” (section 1, p.1). The model exactly recovers the human-selected theorem on 19.6% of held-out proofs, extracts 1,907 valid new theorems from expanded examples and 16 from original set.mm proofs, and refactors 14,092 of 27,220 library theorems.

technique 1: turn theorem extraction into graph labeling

Use this when proofs are trees and a reusable lemma is represented by a connected embedded proof. Construct each proof as a graph G=(V,E); node features concatenate the applied name N and resulting proposition PROP. Label nodes in the target embedded theorem 1 and all others 0. Train a graph neural network to output one probability per node with normalized binary cross entropy. The paper defines the task explicitly: “The task is to output a subset of nodes Vtarget ⊂ V that correspond to an embedded proof of a useful theorem.” (section 4.2, p.5).

Steps from the paper: (1) represent every proof as a tree whose leaves are premises and whose internal nodes apply axioms or theorems (section 3); (2) choose a connected subtree that satisfies the paper’s validity conditions, rather than assuming connectivity alone is enough (section 4.1); (3) label its nodes and train the classifier with the displayed loss (section 4.2). Inference: in Verus, the analogous target is a contiguous proof obligation or reusable lemma body, but Verus proofs are Rust functions and SMT assertions rather than Metamath substitution trees; one would represent requires/ensures, calls, and proof steps as a dependency graph, then use the model only to propose a candidate lemma. The candidate still must be checked by Verus; the graph classifier is not evidence of soundness.

Evidence: the largest model (10 GraphSage layers, hidden size 512, 4,535k parameters) obtains 85.6% test node accuracy and 19.6% test proof accuracy (Table 2, section 5.3, p.7; denominator is the held-out theorem-extraction test set). An ablation shows bidirectional edges plus node features reaches 13.3% test proof accuracy, while no edges plus features reaches 0.1% (Table 1, same section). These results support using both syntax/proposition features and proof connectivity. Assumptions and failure: independent node decisions often produce disconnected predictions; the authors write, “We hypothesize this may be because our current model makes independent node-level predictions.” (section 5.4, p.8). A learned label can also be a connected but invalid subtree, so a verifier is mandatory.

technique 2: synthesize training targets by proof expansion

Use this when human proofs invoke a theorem but the desired training input should contain its expanded body. For each theorem application, duplicate the invoked theorem’s proof tree, substitute its canonical hypothesis leaves with the actual argument nodes, and replace the application node with that instantiated tree. The paper’s three-step description is: “identifying the proof tree associated with the theorem”, “substituting the original arguments with the actual ones in the proof context”, and “finally copy and replace it to where the expanded node is located” (section 4.3, p.5). The expanded copy is the positive target Vtarget.

Apply it as follows: (1) for each application t in proof P, retrieve Pt; (2) map each formal hypothesis leaf in Pt to the corresponding actual parent of t; (3) copy Pt with those substitutions; (4) splice the copy at t, retaining the rest of P; (5) mark the copied connected component as the label 1 example. The implementation expands one theorem at a time, producing M examples for M theorem applications; recursive or simultaneous expansion is left for future work (section 4.3).

Inference: Verus could generate analogous training data by replacing a verified lemma call with its proof-level dependency summary or body, while preserving typed Rust expressions and quantified facts. Rust macro expansion is not equivalent: Verus’s proof functions and SMT context do not expose a Metamath-style canonical substitution tree. The resulting candidate lemma must be rechecked with verus; only checker acceptance is trusted.

Evidence and limits: from the set.mm version containing 27,220 theorems, filtering proofs over 1,000 nodes or node features over 512 characters produced 257,264 raw data points; occurrence balancing and target-wise splitting yielded 124,294 expanded proofs (section 5.1, p.6). Targets are non-overlapping across train/validation/test to reduce memorization. This is a synthetic-data assumption: performance may differ on proofs whose expansion pattern is unlike these examples.

technique 3: validate predicted components and turn them into lemmas

Use this after model prediction, before adding any theorem to a library. First reject disconnected node sets. Then apply the Appendix A.1 conditions to determine whether the connected component is a valid proof, and standardize/deduplicate accepted theorems. The paper reports three categories—“Non-Tree & Invalid”, “Tree & Invalid”, and “Tree & Valid”—and says the last “corresponds to a prediction that leads to an extraction of new theorem previously not defined by humans” (section 5.4, p.8).

Inference: this is the closest direct transfer to VL: propose a Verus lemma, invoke Verus as the acceptance oracle, discard failures, and canonicalize equivalent statements. Do not treat a language model’s probability as proof. Verus’s trusted base remains its verifier/SMT assumptions and any explicitly trusted external bodies; generated text is untrusted until checked.

Evidence: after deduplication and removing 302 whole-proof extractions, 1,923 unique new theorems remained: 1,907 from expanded data and 16 from original set.mm (section 5.4, p.8). Table 3 gives denominators: on the test set, 4,822 predictions consisted of 1,206 non-tree-invalid, 3,348 tree-invalid, and 328 tree-valid; these sum to 4,882, so the table’s row is internally inconsistent by 60. This contradiction should be retained rather than silently corrected. Across accepted theorems, 684 were used in refactoring, with 159,376 total uses and 407,539 nodes saved (Table 5, p.9). The validation procedure is therefore productive but prediction validity is a substantial bottleneck.

technique 4: refactor proofs by matching and replacement

Use a mined theorem library to shorten existing proofs. Alternate matching each extracted theorem against proof subtrees and replacing each match with a theorem application. The paper states: “we consider a specific re-writing procedure, which alternates between 1) matching the extracted theorems against the proofs in the library and 2) replacing the matched proportion of the proofs with the application of the new theorems” (section 5.5, p.9). In Verus, inference: a tool could match normalized assertion/dependency patterns and replace repeated proof blocks with a lemma call, then rerun Verus and measure proof text or solver cost; matching must respect Rust types, lifetimes, triggers, and quantifier instantiation.

Evidence: 14,092/27,220 set.mm theorems were refactored. The 684 used extracted theorems saved 407,539 nodes total; expanded-source theorems averaged 196.7 nodes saved and original-source theorems averaged 2,025.8 (Table 5, p.9). These denominators and source categories matter: the high average is for only 14 original-source theorems, not all 684.

technique 5: train a prover on the refactored library

Use accepted new lemmas as additional training material. Train one Holophrasm prover on the original data and another on the augmented refactored data, with identical defaults and a five-minute search limit per test theorem. The paper reports: “by training on the refactored dataset, the prover was able to prove 75 more test theorems” (section 5.6, p.9). Table 4’s denominator is 2,720 held-out test theorems: Holophrasm’20 proves 557, MetaGen 600, and REFACTOR 632; 632−557=75. New theorems occur in 31.0% of REFACTOR’s proved test theorems, across 141 distinct new theorems (section 5.6).

Inference: for VL, the analogue is retrieval/training over checker-accepted Verus lemmas followed by proof search and final verification. The experiment does not establish soundness beyond Metamath’s checker, nor does it show gains on Rust programs, concurrency, or adversarial generated code. Threat to an agent-written verified-Rust product: medium. REFACTOR can expose repeated proof structure and generate reusable-lemma candidates, reducing proof maintenance, but it cannot replace Verus checking and its training distribution is mathematical Metamath rather than Rust systems code.

what is proved, trusted, and already done

The paper proves validity only for candidates accepted by its Metamath verification algorithm and measures classifier accuracy, extraction counts, compression, and prover test counts. It trusts Metamath’s existing theorem database, the proof checker, the learned model implementation, and experimental preprocessing. It does not prove that neural predictions are sound, that extracted lemmas are semantically useful outside set.mm, or that compression improves runtime. Existing symbolic lemma mining and prover baselines are explicitly compared; VL should not redo a generic claim that graph structure can encode proof reuse. The open VL work is typed Rust/Verus graph extraction, checker-gated mining, and evaluation on real agent-generated code.

techniques for the catalog

  • graph labeling of embedded proofs — classify proof-tree nodes with a feature-aware GNN to propose reusable connected components
  • proof expansion — inline a theorem body with substituted hypotheses to synthesize positive extraction examples
  • checker-gated lemma mining — reject disconnected or invalid predictions, canonicalize accepted components, and retain only verified theorems
  • proof refactoring — repeatedly match extracted lemmas and replace matching subtrees with calls
  • verified-library training — train proof search on checker-accepted, refactored proofs and measure held-out theorems proved Checked 2026-10-15 against paper zhou2024refactor: full comparison completed; metadata and unsupported claims reviewed; experiments not reproduced

Last edited: