TL;DR
The authors introduce LeanHammer, the first end-to-end, domain-general "hammer" tool for the Lean proof assistant. By combining a novel neural premise selector (LeanPremise) with symbolic automated theorem provers, the system can automatically complete complex formal proofs, solving significantly more goals than previous state-of-the-art methods while adapting dynamically to a user's local code.
What Problem Does This Paper Address?
Formal verification—the process of using software like Lean to prove that mathematical theorems or computer programs are correct—is notoriously tedious. One of the biggest bottlenecks is premise selection: out of a library of hundreds of thousands of existing lemmas and definitions, which few are actually needed to prove the current goal?
In other proof assistants like Isabelle, "hammer" tools have long automated this process by picking premises, translating the problem for external solvers, and reconstructing the proof. However, Lean (despite its massive popularity in the math community) has lacked a robust, domain-general hammer. Existing Lean tools often struggled to generalize to new mathematical domains or failed to account for "local" lemmas defined by a user in their current file.
Methods: The LeanHammer Pipeline
The researchers built a three-stage pipeline integrated directly into Lean to bridge the gap between neural retrieval and symbolic reasoning.
- LeanPremise (Neural Selection): Instead of simple keyword matching, the system uses an encoder-only Transformer model to embed the "goal" and all "available premises" into a high-dimensional space. It then retrieves the top-$k$ most relevant premises using cosine similarity.
- Translation: The selected premises and the goal are translated from Lean’s complex "Dependent Type Theory" into "Higher-Order Logic" using a tool called
Lean-auto. - Symbolic Search & Reconstruction: The translated problem is sent to powerful external solvers like Zipperposition. If a solver finds a proof, an internal Lean tool called Duper attempts to "reconstruct" that proof back into Lean’s native language so it can be formally verified.
The "Secret Sauce": Hammer-Aware Data Extraction
Unlike previous models that only look at the next step in a proof, LeanPremise is trained on "hammer-aware" data. The authors extracted every premise used to finish a proof, including implicit ones called by automation (like simp or rw). They also used a normalized serialization—stripping away custom notations and using fully qualified names (e.g., Complex.I instead of just I)—to ensure the model isn't confused by how a user chooses to display their code.
Datasets
- Mathlib: The primary dataset is Lean’s massive mathematical library. The authors extracted nearly 470,000 proof states from over 200,000 theorems.
- miniCTX-v2: To test how well the tool generalizes to mathematics it hasn't seen before, they evaluated it on this benchmark, which contains theorems from diverse areas like the Carleson operator and Fermat’s Last Theorem.
Key Insights and Ideas
- Retrieval for "The End," not "The Next Step": Most neural theorem provers try to predict the very next tactic a human would type. LeanHammer instead asks: "What set of facts, if given to a computer, would allow it to finish the proof entirely?" This shift in objective significantly improves the utility of the retrieved premises for automated solvers.
- Neural + Symbolic = Stronger Together: The paper shows that neural models and symbolic methods (like the MePo selector) have complementary strengths. When used together, they solve a much wider array of problems than either could alone.
- Dynamic Adaptation: A major engineering win is the tool's ability to handle "new" premises. When a user defines a local lemma, LeanHammer embeds it on the fly and adds it to the searchable index, making it immediately useful for subsequent proofs.
Key Results
LeanHammer demonstrates state-of-the-art performance in automated theorem proving within Lean, significantly outperforming existing baselines.
- Superior Performance: LeanHammer (using the "large" 82M parameter model) achieved a 33.3% cumulative proof rate on the Mathlib test set.
- Significant Gains: It solved 21% more goals than the previous best-performing premise selectors (like MePo or ReProver).
- Robust Generalization: On the out-of-distribution
miniCTX-v2benchmark, LeanHammer maintained strong performance, proving that it isn't just memorizing Mathlib but actually "learning" how to relate mathematical concepts. - Efficiency: The entire pipeline is fast enough for real-time use, typically returning a result in under 10 seconds.
Limitations and Future Work
While a major step forward, LeanHammer still faces hurdles:
- Translation Gaps: Some features of Lean’s dependent type theory are difficult to translate into the logic used by external solvers, causing the "hammer" to fail even if the right premises are found.
- Reasoning Limits: The underlying symbolic provers still struggle with specific types of reasoning, such as complex induction or heavy arithmetic, which are common in certain branches of math.
- Proof Reconstruction: Occasionally, an external solver finds a proof, but the internal tool (
Duper) cannot successfully rebuild it within Lean's strict environment.
The authors suggest that future work could involve better "ensembling" of different model sizes and improving the translation layer to capture more of Lean's expressive power.
Summary updated