Introduction
Premise selection is a critical bottleneck in interactive theorem proving (ITP), particularly as libraries like Lean's Mathlib grow to encompass hundreds of thousands of theorems. Existing retrieval methods primarily rely on text-based search or semantic embeddings (such as Large Language Models). However, mathematical formulas are inherently highly structured. Semantic embeddings often fail to capture the precise syntactic and structural alignments required to apply a theorem in a strict formal environment, leading to inaccurate retrieval and wasted computational effort.
To address this, researchers have proposed a novel tree-based framework for premise selection in the Lean 4 theorem prover. By explicitly modeling mathematical expressions as trees and utilizing a multi-stage filtering pipeline, this method significantly outperforms existing semantic embedding-based retrieval tools, offering a more precise way to automate theorem proving.
A Structure-First Methodology
The authors propose a "structure-first, semantics as complement" approach. Instead of treating theorems as flat text, they parse Lean expressions into hierarchical trees. To remove redundancies and simplify the representation, they apply Common Subexpression Elimination (CSE).
Once the expressions are structured as trees, the system employs a two-stage retrieval pipeline to balance speed and precision:
- Stage 1: Coarse Filtering (Speed): To quickly narrow down the search space of over 200,000 theorems, the system uses the Weisfeiler-Lehman (WL) kernel. This training-free graph algorithm iteratively aggregates node information to create a structural feature vector for each tree, allowing for rapid cosine similarity computations. To further accelerate this stage, offline K-Means clustering is used to restrict searches to relevant "neighborhoods" of theorems.
- Stage 2: Refined Filtering (Precision): For the top candidates retrieved in Stage 1, the system calculates Tree Edit Distance (TED)—the minimum cost to transform one tree into another. The authors customized the insertion and deletion costs specifically for Lean's syntax (e.g., assigning lower penalties for swapping simple variables compared to changing core logical structures).
- Adaptive Fusion: The final ranking is determined by a weighted combination of the WL cosine similarity, TED, a custom "Collapse-Match" structural alignment score, and the Jaccard similarity of constant nodes. This final metric ensures that the theorems share a foundational semantic vocabulary.
Datasets and Evaluation
To evaluate their method, the authors built a structured theorem library extracting 217,555 valid theorems from Lean 4’s Mathlib4. They introduced two distinct test sets:
- Test Set A: 100 manually crafted, small-scale problems designed to test specific structural variations, such as variable substitution or condition swapping.
- Test Set B: A large-scale benchmark of 6,119 real-world
(proof state, theorem)pairs. These were automatically extracted from the Lean environment by tracking invocations of theexacttactic, providing a highly realistic ground truth for what a user actually needs at a specific point in a proof.
Key Insights and Results
The experimental analysis yielded several compelling insights into the nature of automated theorem proving:
- Structure Outperforms Pure Semantics for Exact Matches: When a proof requires an exact tactic application, the "shape" of the formula matters just as much as its meaning. Tree-based matching captures this perfectly, whereas LLMs often hallucinate or suggest semantically similar but syntactically incompatible lemmas.
- Superior Accuracy: On the large-scale Test Set B, the tree-based method achieved a Recall@10 of 28.7%, significantly beating the next best baseline (Lean State Search at 22.0%) and purely semantic tools like Moogle (13.6%).
- Efficiency Gains via Two-Stage Pipelines: Tree Edit Distance is highly accurate but computationally expensive ($O(N^2)$). Using the fast WL kernel and clustering to filter the database down to a small candidate pool makes deep structural matching feasible for massive libraries. The cluster-based search space optimization delivered a 2.13x speedup (dropping average query time from ~31 seconds to ~14.5 seconds) with only a marginal trade-off in recall.
- Semantics Still Matter: Ablation studies showed that removing the Jaccard similarity of
Constnodes (which measures shared mathematical vocabulary) caused the most significant performance drop. This proves that while structure is paramount, it must be grounded by basic semantic overlap.
Limitations and Future Work
The primary limitation of this approach stems from Lean's internal compiler mechanics. Lean automatically inserts implicit instance conversions and unfolds definitions (e.g., treating n+1 and n.succ as mathematically equivalent). Because the proposed method strictly compares tree structures, these compiler-level changes can cause semantically identical expressions to have vastly different tree shapes, occasionally confusing the algorithm.
For future work, the authors suggest exploring deeper normalization techniques—such as $\alpha$-equivalence or $\beta$-reduction—before encoding the trees. They also plan to develop similarity algorithms capable of recognizing and ignoring compiler-inserted structures that do not affect the core mathematical meaning, alongside further database-level speed optimizations.
Summary updated