TL;DR
LEANGRAPHSEARCH is a novel retrieval framework for Lean 4 that moves beyond simple semantic matching by exploiting the structural dependency graph of mathematical libraries. By using personalized PageRank to traverse multi-hop dependencies, it uncovers crucial supporting lemmas that share little lexical similarity with a target theorem, leading to a 40% improvement in end-to-end proof success rates compared to vanilla LLM provers.
What Problem Does This Paper Address?
In the world of formal theorem proving, finding the right "building blocks"—definitions, lemmas, and theorems—within a massive library like Lean’s Mathlib is a major bottleneck. Existing retrieval systems primarily rely on semantic or lexical similarity: they look for library items that "sound like" the target theorem or the current proof state.
However, formal mathematics is deeply hierarchical. A high-level theorem might depend on a low-level lemma that looks nothing like it. For example, a query about "morphisms between functors" might semantically match a specific constructor like NatTrans.mk, but the prover actually needs the parent declaration CategoryTheory.NatTrans. Semantic search often misses these "multi-hop" dependencies, leaving automated provers stranded without the necessary tools to complete a proof.
Methods
LEANGRAPHSEARCH addresses this by treating Mathlib as a directed dependency graph where nodes are declarations and edges represent formal references (e.g., theorem A uses definition B in its proof or statement).
The retrieval process follows a three-stage pipeline:
- Semantic Seed Retrieval: The system uses a standard embedding-based retriever (Qwen3-Embedding-8B) and a reranker to find an initial set of "seed" declarations that are semantically similar to the query.
- Query-Aware Propagation: Using these seeds as starting points, it performs Personalized PageRank (PPR) on the dependency graph. This propagates relevance scores along the edges, effectively "expanding" the search to include premises that the seeds depend on, even if those premises aren't lexically similar to the original query.
- Candidate Refinement: The expanded candidate set is merged with the original seeds and reranked one final time. The final score combines the reranker's semantic score with the graph-based PPR score.
The authors also integrate this retriever into an agentic proving loop that uses iterative reflection. If a proof attempt fails, the LLM prover receives Lean compiler feedback and can issue new search queries to find missing lemmas. They also introduce an optional Failure Memory to prevent the prover from repeating the same unsuccessful proof strategies.
Datasets
The authors evaluate their method on several specialized benchmarks:
- MathlibQR: 810 natural-language queries paired with single target declarations.
- MathlibMPR: 69 research-level theorems requiring multiple premises grouped into alternative proof routes.
- FATE-H: 100 graduate-level algebra problems.
- MathlibMPR-Prop: 50 propositions from MathlibMPR adapted for tactic-mode proving.
- Lean-IMO-Bench: 60 problems from International Mathematical Olympiad (IMO) levels (Basic and Advanced).
Key Insights and Ideas
- Structure Trumps Surface Similarity: The "aha moment" is that the formal structure of a library is a more reliable map than natural language descriptions. Graph traversal can bridge the "lexical gap" between a high-level goal and the low-level machinery required to prove it.
- Constructors as Gateways: Semantic search is good at finding specific constructors (e.g.,
Matroid.mk), but graph expansion is what successfully leads the prover to the essential parent objects (e.g.,Matroid) that the prover actually needs to reference. - Concentrated Context: Rather than just providing more lemmas, graph search provides better-composed sets of lemmas. On MathlibMPR, LEANGRAPHSEARCH was found to return fewer "filler" declarations, instead concentrating the specific premises needed for a complete proof route within the top results.
- Efficiency Gains: By finding the right lemmas faster, the system reduces the number of "reflection turns" (iterations) needed, significantly lowering the API cost per solved problem.
Key Results
- Retrieval Performance: On MathlibQR, LEANGRAPHSEARCH improved Recall@100 by 12 percentage points (94.7% vs 82.7%) over the previous state-of-the-art, LeanSearch v2.
- Proving Success: In end-to-end proving on the FATE-H benchmark, the system achieved an 81% success rate, an 8 percentage point improvement over LeanSearch v2 and a massive jump from the 52% success rate of a prover with no retrieval.
- Cost Efficiency: As shown in Figure 3, LEANGRAPHSEARCH achieved the lowest API cost per solved problem across 210 instances, proving that better retrieval leads to more efficient reasoning.
Limitations and Future Work
- Directionality: The current graph only uses forward dependencies (what a theorem uses). The authors suggest that incorporating backward dependencies (what uses this theorem) could help find related theorems that solve similar problems.
- Static Graph: The dependency graph is currently static, based on a fixed version of Mathlib. A more dynamic system that updates the graph as a user adds new local lemmas during a proof session would be a powerful extension.
- LLM Dependency: While the graph search is algorithmic, the final reranking and the proving loop still rely heavily on the underlying LLM's reasoning capabilities. Improvements in base models will likely further amplify the gains from structural retrieval.
Summary updated