Lean Refactor: Multi-Objective Controllable Proof Optimization via Agentic Strategy Search
Lean Refactor is a retrieval-augmented agentic framework that optimizes Lean proofs for multiple objectives—including token compression, compilation speed, and version compatibility—by dynamically selecting curated refactoring strategies without requiring model retraining.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
The Problem: The "Over-Engineered" Proof
Imagine a brilliant but overly enthusiastic architect (the AI) who has just built a house (a mathematical proof). The house is structurally sound—it won't fall down, and it passes all safety inspections. However, the architect used 500 bricks to build a wall that only needed 50. They used a sledgehammer to crack a nut.
In the world of Lean (a language used to write mathematical proofs that computers can verify), AI models often produce proofs that are correct but incredibly long, messy, and slow to compile.
- Too Long: The proof is hard for humans to read.
- Too Slow: Because the proof is bloated with unnecessary steps, it takes a long time for the computer to check if it's valid.
- Fragile: The Lean language changes frequently (like software updates). A proof written for "Version 1.0" might break completely when the computer updates to "Version 2.0," even if the math is still right.
Existing tools tried to fix this by either retraining the AI (which is expensive and slow) or just asking it to "be shorter" (which often makes the proof slower to run).
The Solution: The "Smart Librarian" System
The authors created Lean Refactor. Instead of trying to retrain the AI, they built a "plug-and-play" system that acts like a super-smart librarian for the AI.
Here is how it works, using a metaphor:
1. The Strategy Bank (The Library)
Imagine a massive library filled with "Refactoring Cards." Each card describes a specific trick to shorten a proof.
- The Trick: "Instead of listing every number one by one, use this one magic formula."
- The Metadata: Crucially, every card has a label. It says:
- How much time does this save? (e.g., "Saves 30% compilation time").
- Which version of the language does this work on? (e.g., "Works on Lean v4.16 and v4.22").
- How much shorter does it make the proof?
The paper claims they built the largest library of these cards ever, containing over 9,000 unique strategies distilled from hundreds of thousands of proof examples.
2. The Agent (The Architect + The Librarian)
When the AI needs to fix a proof, it doesn't guess. It follows a loop:
- The Planner: The AI looks at the messy proof and says, "This section looks like it needs a 'Magic Formula' trick."
- The Librarian (Retrieval): The system goes to the library and pulls out the specific cards that match that section.
- If you want the shortest proof: It pulls cards that promise the biggest size reduction.
- If you want the fastest compilation: It pulls cards that promise the biggest speed boost.
- If you are using an old version of Lean: It filters out any cards that won't work on your version.
- The Refactorer: The AI applies the trick from the card to rewrite the proof.
- The Debugger: The computer checks the new proof. If it breaks, the AI tries to fix the error locally without undoing the whole improvement.
Why This is Special (The Paper's Claims)
1. It balances competing goals (The "Multi-Objective" Magic)
Usually, you have to choose: "Do I want the proof to be short, or do I want it to compile fast?"
- Old Way: You pick one, and the other suffers.
- Lean Refactor: You can tell the system, "I want it short, but also fast." The system looks at the library cards, sees which ones offer both, and picks the best balance.
- Result: On competition math problems, they shrank proofs by over 70% and cut compilation time by over 60%.
2. It survives software updates (The "Version Robustness")
Because the library cards are labeled with the specific software versions they work on, the system can instantly filter out "outdated" tricks.
- Result: If you ask for a proof for "Lean v4.16," the system only uses cards that work for v4.16. This prevents the AI from hallucinating (making up) tools that don't exist in that version.
3. It works with any AI (The "Model Agnostic" Feature)
You don't need to train a new AI for this. The system works with any "frozen" (pre-trained) AI model, whether it's from Google (Gemini), Anthropic (Claude), or OpenAI (GPT). The "intelligence" comes from the library of strategies, not from the AI's brain.
- Result: They tested it on different AI models, and it improved the performance of all of them, even beating a specialized coding agent called "Claude Code."
The Bottom Line
Lean Refactor is like giving a construction crew a set of blueprints and a toolbox of pre-tested, labeled shortcuts. Instead of guessing how to build a house, they look up the best way to build a specific wall based on the tools they have and the version of the building code they are using.
The paper claims this approach:
- Shrinks proofs by 70%+ on math competitions.
- Makes them compile 60% faster.
- Keeps them working even when the software language updates.
- Does all this without needing to retrain the AI models.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.