arXiv:2610.22339cs.LGOct 2026

Manuscript Offprint

arXiv:2610.22339

Lean Graph Search for Formal Theorem Proving

Yihan Xu, Jia-Chen Gu, Junyi Zhang, Di Wu, Haikang Deng, Po-Nien Kung, Kai-Wei Chang, Amit Sahai, Wei Wang, Nanyun Peng

ABSTRACT

Retrieving relevant lemmas is crucial for formal theorem proving, enabling provers to build machine-checkable proofs from established mathematical results. Recent retrieval systems match library declarations to a target theorem or its intermediate proof steps, but make limited use of multi-hop dependencies among declarations. These dependencies can reveal supporting lemmas that are not necessarily lexically similar to the target theorem but recur in proofs of related problems. To this end, we propose LEANGRAPHSEARCH, a graph-based retrieval method for Lean 4 that constructs a graph from Mathlib's forward dependencies and traverses it to uncover supporting lemmas through multi-hop dependency chains. Specifically, LEANGRAPHSEARCH links each declaration to the premises it depends on, uses a graph-based ranking algorithm to propagate relevance from semantically matched declarations to their dependencies, and reranks the expanded candidates against the original query. Across two mathematical retrieval benchmarks, LEANGRAPHSEARCH improves recall by up to 12 percentage points over the strongest baseline, LeanSearch v2, on MathlibQR and increases coverage of complete annotated proof routes on MathlibMPR by up to 3.7 percentage points. More importantly, we evaluate whether these retrieval gains translate into improved end-to-end theorem proving by integrating LEANGRAPHSEARCH into an iterative proving loop guided by Lean feedback. Across three theorem proving benchmarks, LEANGRAPHSEARCH improves pass rate at {8,16,32}\{8, 16, 32\} reflection turns by as much as 40% compared to the vanilla prover and at most 10% compared to LeanSearch v2, showing a better accuracy-cost tradeoff. These findings highlight the value of dependency graph search for theorem proving and motivate further research on structure-aware search for proof discovery.

1 INTRODUCTION

Formal theorem proving expresses mathematical statements and proofs in a formal language, allowing a proof assistant such as Lean to verify their correctness (de Moura & Ullrich, 2021). Search engines support the proving process by helping users and automated provers locate useful definitions, theorems, and lemmas within large mathematical libraries such as Mathlib (The mathlib Community, 2020; Yang et al., 2023; Mikuła et al., 2024; Shen et al., 2025; Ju et al., 2026). Existing retrieval systems, such as LeanExplore (Asher, 2025), LeanFinder (Lu et al., 2026), and LeanSearch v2 (Gao et al., 2026), address this need by identifying library declarations relevant to a target theorem or an intermediate goal. However, their limited use of multi-hop dependencies among declarations may miss supporting lemmas that share little lexical similarity with the query but occur in proofs of related problems (Shen et al., 2025; Gao et al., 2026).

A key observation is that declarations relevant to a target theorem can serve as starting points for discovering supporting lemmas through multi-hop dependencies. These dependencies connect declarations to their direct and indirect premises, providing extra paths to useful lemmas that are less

∗^{*} Equal contribution.

(a) Declaration Dependencies

Figure

(b) Retrieval and Proving

Figure

Figure 1: Dependency-guided retrieval with LEANGRAPHSEARCH. (a) An illustration of the dependency graph, showing how semantically retrieved declarations (blue) lead to supporting premises (green) through shared and multi-hop dependencies. (b) Selected retrieval and proving results. Gains are reported in percentage points relative to LeanSearch v2.

lexically similar to the query. To capture and exploit this structure, we introduce LEANGRAPH-SEARCH (Fig. 1), a graph-based retrieval framework for Lean 4 theorem proving. It constructs a directed graph from Mathlib's forward dependencies, representing declarations as nodes and linking each declaration to the premises it directly depends on. Searching this graph from semantically relevant declarations extends retrieval beyond direct query matching, helping users and automated provers discover supporting premises that may otherwise be difficult to locate.

To search the constructed dependency graph, LEANGRAPHSEARCH uses the target query to guide traversal along formal dependencies. Given an informal description or a formal goal, it first retrieves declarations using embeddings and reranks them against the query to select semantically relevant seeds. The seed relevance scores are normalized to form the personalization distribution for personalized PageRank (Brin & Page, 1998), which propagates relevance along dependency edges while repeatedly returning to the seeds, thereby expanding the candidate set. Finally, LEANGRAPHSEARCH reranks the expanded candidates against the original query and combines these second-pass relevance scores with query-specific graph scores to produce the final ranking.

We evaluate LEANGRAPHSEARCH on both standalone premise retrieval and downstream formal theorem proving. For premise retrieval, LEANGRAPHSEARCH improves Recall@100 from 82.7% with LeanSearch v2 to 94.7% on the 810-query fair subset of MathlibQR (Gao et al., 2026), confirming that dependency graph search effectively recovers additional relevant lemmas. On MathlibMPR (Gao et al., 2026), it improves proof route-level premise coverage, increasing Covered@20 from 39.1% to 42.8% and Covered@50 from 41.3% to 44.2%. These results suggest that dependency-aware retrieval better recovers complete premise sets along annotated proof routes. For formal theorem proving, we integrate LEANGRAPHSEARCH into an iterative proving loop equipped with Lean's diagnostic feedback and problem-local failure memory. LEANGRAPHSEARCH consistently outperforms the state-of-the-art retrieval baselines across FATE-H (Jiang et al., 2026), MathlibMPR-Prop (Gao et al., 2026), and Lean-IMO-Bench (Kung et al., 2026), demonstrating that premise retrieval improvements translate into higher formal proof success rates.