- Rating
- 4
- Clarity
- 3
- Confidence
- 4
- Originality
- 3
- Quality
- 3
- Significance
- 3
Read review
Summary
The paper introduces Lean Refactor, a retrieval-augmented agentic framework that optimizes Lean proofs with respect to proof complexity, compilation time and version compatibility. The framework first constructs a strategy bank from long-short proof pairs, each annotated with metadata of compilation time and version compatibility. Then, it employs a fine-tuned LLM retriever that chooses strategies based on the input proof fragments. The retrieval process can be conditioned on optimization objectives during inference time. The evaluation shows that LLM Refactor achieves higher reduction ratio in both proof complexity and compilation time, while making the proof compilable under different versions.
Strengths and weaknesses
Strength
- Lean Refactor is effective in simplifying long proofs as shown in the experiments. This can be very helpful for making proofs more readable and accessible for Lean users.
- I like the idea of having a strategy bank, which essentially mimics the design of compilers that have different optimization passes / rewrites. This makes individual strategy amendable for verification to guard their soundness.
- Lean refactor targets cross-version compatibility issues, which I believe is a big concern for today’s LLM-based proof and code generation, as both Mathlib and CSlib are under active development.
Weaknesses
- Motivation on compilation time needs more justification: The proofs are usually compiled once and re-used in other modules, so the relevant question is whether running Lean Refactor plus compiling the optimized proof is cheaper than compiling the original. The experiments also do not report the statistics for scale of re-compilation needed after applying Lean Refactor.
- No comparisons against symbolic techniques. The evaluation does not compare with any symbolic techniques such as rewriting-based optimizations, proof decomposition and parallel compilation. This left the question whether Lean Refactor can bring more benefit than well-known sound techniques unanswered.
- The version-compatibility contribution is not clearly differentiated: given there is an extensive body of work on term rewriting, including the existing Lean infrastructure of
deprecatedTodecorations (lean4/DeprecatedTo), the compatibility issue could be soundly addressed via these mechanical rewrites. Therefore, I found this point of contribution is not clearly differentiating and would like the authors to clarify what are the additional benefits Lean Refactor brings beyond these approaches.
Questions
Besides the above questions:
- Lean Refactor focuses heavily on mathematical proofs. I wonder if similar techniques can be applied to proofs about programs, as there are increasing volumes of work on verified code generation. In these tasks, people may invoke SMT / theory solvers (e.g, CVC5) in the middle of proof scripts. I think under this setting, compilation time is a concern since the solvers may diverge and a manual proof needs to be substituted in.
- Does Lean Refactor consider any global refactor other than local rewrites? Appendices D and M only show examples on mutating / rewriting local tactics, but a global rewrite, e.g., extracting
haves into sub-files and enabling parallel elaboration and compilation, could also potentially yield speed-ups: some global structural rewrites can make the verification task compositional, and compositionality is usually the key to scalability. - While the paper appendix shows the aggregated cost, what approximately is the minimum budget the user has to allocate for Lean Refactor to be effective? What is the per-theorem cost and the cost with respect to the input theorem complexity?
Limitations
yes
Paper formatting concerns
No particular concern
Final justification
Major concerns resolved - the author clarified the positioning w.r.t. downstream applications and impact (Mathlib CI); provided additional results on non-math proofs, demonstrating the generality, while minor points such as discussions on related symbolic approaches (Tactic Script Optimisation, CPP'25, Proof Refactoring 2013, Proof Repair 2021) remain. They can be addressed through writing.
We thank Reviewer odxM for the time and effort in reviewing our paper, and for recognizing that Lean Refactor is effective at simplifying long proofs to improve readability for Lean users, that the strategy bank is an interesting design that keeps individual strategies amenable to soundness verification, and that our cross-version compatibility focus targets a major concern for Lean projects.
We thank the reviewer for raising this point. While compiled modules can be reused when valid cached artifacts are available, compilation cost still recurs throughout active Lean development for three structural reasons:
Continuous integration. Mathlib continuously monitors build performance: Speedcenter benchmarks per-file compilation time on every master commit and flags regressions of at least 5% [1]. The existence of this infrastructure indicates that recurring compilation cost is an important maintenance concern.
File-granularity rebuilding. In batch compilation, Lean rebuilds at the source-file level. Modifying a declaration therefore requires rebuilding its containing file and may invalidate dependent build artifacts, causing expensive proofs to impose recurring costs whenever the module is rebuilt.
Fresh and uncached builds. Clean builds, new branches, version upgrades, cache misses, and bisecting historical commits may require modules to be compiled again. Moreover, shared caches must themselves be produced by machines that perform the corresponding builds.
Break-even. Refactoring pays off when N × ΔT > C (N rebuilds, ΔT per-compile saving, C one-time refactoring time cost). With Table 4's savings, break-even is N ≈ 60 rebuilds, easily reached for an active repo.
Re-compilation after applying Lean Refactor: During the optimization process, the agent interacts with the Lean compiler when needing to check correctness of the optimized proof. The average count of compiler calls is 22 per theorem during optimization process. No recompilation is needed after using Lean Refactor.
Finally, some evaluated proofs were supplied by repository maintainers after we contacted them, confirming that proof optimization of length and heartbeat addresses a pain point the community actively cares about.
[1] Baanen et al., "Growing Mathlib: maintenance of a large scale mathematical library" 2025.
To our knowledge, no existing symbolic tool performs Lean 4 proof refactoring, and no prior system compares against one, as no such baseline exists.
The techniques named are orthogonal rather than competing: parallel compilation doesn’t change heartbeat, and proof decomposition restructures where work happens without reducing it. Term rewriting (
simplemma sets) is a mechanism for applying a transformation, not for deciding which transformation to apply where.We are happy to add a comparison if the reviewer can point us to a concrete symbolic Lean proof optimization tool.
We address this with three points below:
Deprecation aliases cover only one narrow breakage class: renames of declarations that still exist with unchanged statements. They do not cover removed or merged lemmas, changed signatures or implicit-argument structure, typeclass/instance restructurings, or changes in tactic behavior, all of which break proofs with no deprecation to follow. Mathlib also removes aliases after a limited window, so they cannot bridge the multi-version intervals we target.
The empirical evidence that mechanical rewrites are insufficient is direct. Despite this infrastructure existing, downstream projects must pin to Mathlib's exact toolchain [1]. Moreover, in Table 9, 54 of 194 original miniF2F proofs fail to compile by v4.29.0, and these failures include tactic-behavior changes with no renamed declaration to rewrite. If
deprecatedTosoundly solved compatibility, neither would occur.Our contribution is broader than deprecation rewrites can express.
deprecatedToonly migrates names forward, whereas version-filtered retrieval targets any toolchain, including older ones (Table 5), and can supply toolchain knowledge the backbone LLM lacks.[1] https://leanprover-community.github.io/archive/stream/270676-lean4/topic/mathlib4.html
We thank the reviewer for this suggestion and we ran a new experiment on exactly this setting. We evaluate on Strata (strata-org/Strata), an Amazon-backed Lean 4 platform for formalizing programming language semantics and building verification tools, whose pipeline discharges verification conditions via SMT solvers (cvc5, z3), matching the reviewer's described setting. The maintainers, whom we contacted, supplied proofs they wanted optimized. On 40 theorems from 2 files, Lean Refactor achieves a 15.89% average length reduction and a 6.32% average relative heartbeat reduction. These results indicate that our framework works outside of math proofs.
We would like to make two clarifications:
"Local" understates our scope. The planner segments proofs at multiple granularities and can target the entire proof (Section 3.3), and the final rewrites reflect this: across evaluation sets, the median optimized proof has 98% of its proof lines revised or removed, and 42% of optimized proofs share no line with the original, indicating complete rewrites, not local tactic edits. What we deliberately do not do is cross-declaration restructuring such as extracting haves into sub-files: our unit of optimization is the single declaration, which makes every result a drop-in replacement that maintainers can review and accept.
Extraction redistributes work; our refactoring removes it. Parallel elaboration of extracted sub-files can reduce wall-clock time but leaves total work unchanged, and our heartbeat metric is invariant to parallelism. In contrast, our rewrites delete the work itself (e.g., 11% heartbeat reduction on FLT and 48% on PutnamBench). The two are therefore complementary: our savings compound with compositional restructuring, which could itself be encoded as strategies over larger scopes, an extension we will note as future work.
Per-theorem cost with Gemini 3 Flash averages around $0.8, varying with original proof length and style. The minimum effective budget depends on the regime, where competition proofs converge faster, with ~10 api calls already yielding good reduction, while human-written research-level proofs tend to require higher budgets like ~20 - 30.