ImProver: Agent-Based Automated Proof Optimization

Riyaz Ahuja, Jeremy Avigad, Prasad Tetali, Sean Welleck

Introduction

Large language models (LLMs) have become surprisingly adept at generating formal proofs for mathematical theorems in proof assistants like Lean. However, the proofs they generate—and even many human-written proofs in libraries like Lean’s Mathlib—are often "ugly." They can be unnecessarily long, difficult for humans to read, or fragile to future software updates.

ImProver is a new LLM-based agent designed to automatically rewrite formal mathematical proofs to make them shorter, more readable, or more structured. By combining large language models with symbolic feedback from the Lean compiler, it significantly outperforms standard AI models in generating high-quality, verifiable mathematics.

The Challenge: Automated Proof Optimization

The authors identify a novel challenge called Automated Proof Optimization: given a correct proof, how can we rewrite it to optimize for a specific metric (like length or "declarativity") while ensuring it remains logically sound?

This optimization is vital for maintaining massive mathematical libraries and for creating better, cleaner training data for future AI mathematicians. The researchers found that simply asking a standard model like GPT-4o to "make this proof better" usually fails; the model frequently introduces logical errors or fails to find meaningful optimizations.

Methods: The ImProver Agent

To tackle this, the researchers built ImProver, an agentic framework featuring several key innovations:

  • Chain-of-States (CoS) Prompting: This is the system's core innovation. Standard LLMs only see the "tactics" (the commands). ImProver uses Lean’s metaprogramming to extract the actual mathematical state (the hypotheses and goals) at every single step and feeds that back into the LLM as comments. This grounds the model’s reasoning in the actual symbolic reality of the proof.
Chain-of-States Prompting Example
  • Iterative Refinement: If the model generates a proof that doesn't compile, ImProver captures the error message and asks the model to fix it, repeating this process until the proof is valid.
  • Retrieval-Augmented Generation (RAG): The system searches through Lean’s documentation and existing mathematical libraries to find relevant lemmas or syntax examples to help the model optimize the specific theorem at hand.
  • Custom Metrics: The authors defined specific mathematical rewards, such as the Length Metric (minimizing the number of steps) and the Declarative Metric (maximizing the use of explicit have statements to make the logic easier to follow).

Datasets

The authors evaluated ImProver across three levels of mathematical difficulty:

  1. Mathematics in Lean (MIL): Undergraduate-level exercises covering set theory, group theory, and calculus.
  2. Compfiles: High-school competition problems from the International Math Olympiad (IMO).
  3. Mathlib: Research-level proofs from real-world mathematical libraries (specifically algebraic topology).
  4. MiniF2F: A standard benchmark used to test the system's ability to generate proofs from scratch.

Key Insights

  • Optimization is Harder than Generation: Making a proof "elegant" is often more difficult for an LLM than simply finding any correct proof.
  • Symbolic Feedback is Essential: Without the "Chain-of-States" context, LLMs struggle to maintain correctness during complex rewrites.
  • Optimization Generalizes to Discovery: A system that is good at optimizing proofs is also excellent at finding them. Given an empty proof (a "sorry" in Lean), ImProver can "optimize" that nothingness into a complete, valid proof, outperforming standard theorem-proving baselines.
  • Avoiding Degenerate Solutions: Models might try to "cheat" metrics (e.g., adding useless have statements to look more declarative). The authors mitigated this by using few-shot examples to teach the model what "good" style actually looks like.

Key Results

ImProver demonstrated massive gains over a baseline GPT-4o model across multiple optimization metrics.

Performance Comparison on Proof Optimization
  • Length Optimization: ImProver achieved a 20.96% average reduction in proof length, compared to just 3.7% for the baseline.
  • Declarativity: It improved the structural clarity of proofs by 9.34%, whereas the baseline only managed 2.21%.
  • Reliability: While the baseline GPT-4o often broke proofs (resulting in low accuracy), ImProver’s selection policy ensured that it always returned a correct proof, successfully improving the metric in roughly 35% of all cases across all datasets.
  • Theorem Proving: On the MiniF2F benchmark, ImProver achieved a 16.39% pass rate, nearly doubling the performance of the base GPT-4o (9.02%).

Limitations and Future Work

The primary limitation of ImProver is cost and latency. Because it relies on multiple calls to proprietary models (like GPT-4o) and iterative refinement, the process is computationally expensive.

Future work will likely focus on "distilling" these capabilities into smaller, open-source models using Supervised Fine-Tuning (SFT) or Reinforcement Learning (RL). This would allow the optimization process to happen locally and much faster, potentially integrating directly into the IDEs that mathematicians use every day.

Summary updated

BibTeX
@inproceedings{ahuja2025improver,
  author = {Riyaz Ahuja and Jeremy Avigad and Prasad Tetali and Sean Welleck},
  title = {{ImProver: Agent-Based Automated Proof Optimization}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=dWsdJAXjQD},
}
Figure