Proof-Refactor: Refactoring Generated Formal Proofs into Modular Artifacts

Yiming Fu Department of Mathematics Southern University of Science and Technology &Peixuan Liu Department of Mathematics Southern University of Science and Technology Zichen Wang School of Mathematical Sciences Peking University &Kun Yuan Center for Machine Learning Research Peking University · 2026

Read Proof-Refactor: Refactoring Generated Formal Proofs into Modular Artifacts by Yiming Fu Department of Mathematics Southern University of Science and Technology &Peixuan Liu Department of Mathematics Southern University of Science and Technology Zichen Wang School of Mathematical Sciences Peking University &Kun Yuan Center for Machine Learning Research Peking University (2026) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2606-03743.txt.

Introduction

Fu, Liu, Wang, and Yuan refactor machine-generated formal proofs into modular, library-grade artifacts. Language models now produce Lean proofs that compile. Their scripts still read worse than library proofs: less modular, less reusable, harder to maintain. A compile-first goal drives that gap. Length-based scores miss the higher-level qualities that matter.

Proof-Refactoring follows how humans rework proofs instead. Four phases structure the agent's work. Candidate fragments are extracted from the draft. Helper declarations are designed around them. Each piece is then proven formally on its own. The original proof is repaired using the verified parts. On PutnamBench and Putnam2025 proofs, rubric scores beat a strong Claude Code baseline. Gains are largest in signature quality and human readability. The results show process guidance can lift proof structure without chasing length.

Catalog record

CREATORYiming Fu Department of Mathematics Southern University of Science and Technology &Peixuan Liu Department of Mathematics Southern University of Science and Technology Zichen Wang School of Mathematical Sciences Peking University &Kun Yuan Center for Machine Learning Research Peking University
YEAR2026
COLLECTIONPAPERS
FORMATTXT
FILE SIZE66 KB
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2606.03743

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

Proof-Refactor: Refactoring Generated Formal Proofs into Modular Artifacts Yiming Fu Department of Mathematics Southern University of Science and Technology &Peixuan Liu Department of Mathematics Southern University of Science and Technology Zichen Wang School of Mathematical Sciences Peking University &Kun Yuan Center for Machine Learning Research Peking University Abstract While Large Language Models (LLMs) have shown strong performance in generating formal proofs, their outputs often remain less readable, modular, maintainable, and reusable than proofs in mature formal mathematics libraries. We argue that this gap stems in part from the compile-first objective implicit in most proof-generation pipelines, which encourages monolithic or ad hoc proof scripts rather than library-quality artifacts. Existing approaches to proof-quality improvement often rely on explicit, computable optimization objectives. In practice, however, the most tractable and experimentally validated objectives are largely length-based, while higher-level qualities such as readability, modularity, maintainability, and reusability are difficult to reduce to reliable automatic metrics. Instead of optimizing proof improvement against a single proxy metric, we take a process-guided approach inspired by human proof-refactoring workflows. We propose an agentic framework Proof-Refactor that decomposes proof refactoring into four phases: extracting candidate proof fragments, designing helper declarations, formally proving the extracted and designed components, and repairing the original proof using the verified components. On generated Lean proofs from PutnamBench and Putnam2025, Proof-Refactor improves rubric-based refactoring scores over a strong Claude Code refactoring baseline, with the largest gains in signature quality and human readability. These results suggest that process-guided refactoring can improve proof structure without treating proof length as the primary objective. 1 Introduction Formal theorem proving with proof assistants such as Lean ( 4 ) and Isabelle ( 15 ) produces machine-verifiable mathematical proofs. This is useful for verified mathematics and for training LLMs, since proof checking provides a precise reward signal for reinforcement learning (RL). Recent systems have made progress on university-level mathematics, including PutnamBench ( 16 ) and Putnam2025 problems ( 3 ) . However, proof-assistant verification also induces a narrow objective: a generated proof is rewarded primarily for compiling. This binary feedback ensures correctness, but it does not by itself encourage readability, modularity, maintainability, or library integration. An agent may therefore produce a passing proof that leaves reusable arguments inlined, introduces problem-specific definitions instead of using existing ones, or relies on heavy automation and enlarged resource limits rather than factoring the argument into intermediate declarations. This reflects a mismatch between what is easy to check and the broader qualities expected of library-quality formal mathematics. Existing approaches to improving proof quality ( 1 ; 10 ) often rely on computable objectives. In practice, the most reliable automatic objectives are largely length-based, while qualities such as readability, modularity, maintainability, and reusability are difficult to measure. Length-based objectives can also favor direct compression (golfing) over semantically meaningful helper declarations. This distinction mirrors human formalization practice. Humans often first obtain a compiling proof and then refactor it. The central step is not only to reduce length, but to identify reusable proof fragments, generalize them into declarations that fit the surrounding library, prove these declarations from the existing fragments, and rewrite the original proof to call them. Proof golfing is a legitimate part of refactoring in this broad sense, but it is not the whole process: focusing only on golfing misses the helper-oriented workflow that turns local arguments into reusable library components. We therefore view proof refactoring as a structured process rather than end-to-end optimization against a proxy metric. Proof-Refactor does not include a dedicated length-minimization stage; instead, it focuses on extracting, generalizing, and reusing intermediate proof components. We propose Proof-Refactor , a Claude Code-based agentic framework that decomposes Lean proof refactoring into four phases: extracting candidate proof fragments, designing helper declarations, proving the extracted and designed components, and repairing the original proof with the verified components. The framework integrates lean-lsp-mcp ( 6 ) , a custom Lean 4 extract tactic for turning proof fragments into standalone theorems, and external assistance for selecting fragments and designing helper declarations. Experiments on generated PutnamBench and Putnam2025 proofs provide evidence that Proof-Refactor improves refactoring quality over the baseline, with the clearest gains in helper-signature quality, proof structure, reuse of mathematical infrastructure, and human readability. 2 Related work Proof Optimization. A related line of work improves formal proofs through computable objectives, especially proof length ( 1 ; 10 ) . 1 combine LLM search with retrieval-augmented generation (RAG) and Chain-of-States, while ProofOptimizer ( 10 ) trains models with length-filtered data and length-based RL rewards. These systems show that post-generation proof improvement is feasible and can produce synthetic training data for models. Our work targets a complementary form of improvement: helper declarations are the central object of a structured refactoring pipeline, rather than a byproduct of optimizing a metric. Proof Extraction. Another related direction is extracting artifacts from existing formal proofs. REFACTOR ( 19 ) trains a graph neural network (GNN) to identify proof-tree nodes that form extractable theorem components in Metamath ( 14 ) , then standardizes the predicted components into valid theorems. 18 study a more symbolic approach, discovering reusable tactics by searching for recurring, collapsible subgraphs in Tactic Dependence Graphs. These works are closely related to proof refactoring, but extraction alone tends to preserve the form and specificity of the original fragments rather than lifting them into more general, library-style artifacts. This motivates the dedicated helper-design phase in Proof-Refactor, which explicitly revises extracted scaffolds into cleaner and more reusable declarations. Agentic Systems for Theorem Proving. Hilbert ( 17 ) and Numina-Lean-Agent ( 12 ) are open-source agentic systems for formal theorem proving. Hilbert combines informal reasoning, theorem retrieval, formal proving, and verifier feedback to recursively decompose hard goals into subgoals. Numina-Lean-Agent builds on Claude Code and Numina-Lean-MCP, using tools for Lean interaction, retrieval, informal proving, and external-model consultation through a discussion partner. These systems are related to the draft-sketch-prove paradigm ( 11 ) , where informal reasoning supplies high-level proof sketches that guide formal provers toward a complete proof. We adopt two system-level ideas from this line: using Claude Code with lean-lsp-mcp as the Lean interaction substrate, and allowing the agent to consult an external model. However, our use of external assistance is not an informal-to-formal sketching pipeline. Proof-Refactor starts from an existing Lean proof, and external assistance serves as an auxiliary reasoning channel for refactoring decisions over the current formal context, rather than only producing informal proof sketches. Thus, while it is related in spirit to Numina-Lean-Agent’s discussion partner, the goal is to support proof refactoring rather than to produce a proof plan for theorem proving. 3 Refactoring: Task and Evaluation Task Definition. Let E denote the ambient formal environment available to a declaration, including imported library declarations. Given a verified declaration (S,p) , where S is its formal signature and p is its original proof, the initial data are (E,p) , satisfying E\vdash p:S . We formulate an individual refactoring as a constrained transformation (E,p)\leadsto_{\mathrm{refactor}}(E^{\prime},p^{\prime}) : (E,p)\leadsto_{\mathrm{refactor}}(E^{\prime},p^{\prime})\quad\text{s.t.}\quad\begin{cases}E^{\prime}\vdash p^{\prime}:S\\ (E^{\prime},p^{\prime})\succ_{\mathcal{Q}}(E,p)\end{cases} (1) Here, E\vdash p:S means: under the environment E , the proof p of the formal signature S complies. The relation (E^{\prime},p^{\prime})\succ_{\mathcal{Q}}(E,p) states that the refactored proof is preferred to the original proof according to the quality preference \mathcal{Q} . The same preference can also be applied to a finite

Read the complete text