A Semantic Search Engine for Mathlib4
Guoxiong Gao, Haocheng Ju, Jiedong Jiang, Zihan Qin, Bin Dong
TL;DR
This work addresses the challenge of searching mathlib4 with informal queries by building a semantic search engine that converts formal Lean 4 theorems into informal counterparts and indexes them alongside formal statements. The approach uses offline embeddings of informal-formal theorem pairs in a vector store (Chroma DB) with HNSW search, and enhances user queries through LLM-based augmentation to improve semantic matching. A benchmark of 50 queries organized into 18 intent groups evaluates retrieval performance using metrics such as precision and ranking quality, showing that embedding-based retrieval with query augmentation, particularly using the E5_mistral-7b model, yields the strongest overall results. The study also includes ablation analyses on document preparations and query augmentation, demonstrating the value of a combined formal+informal corpus and targeted prompting. Overall, the work offers a practical, scalable framework for Lean 4 theorem search that can accelerate formalization workflows and informs future improvements in informalization guidelines and embedding-based MIR for mathematics.
Abstract
The interactive theorem prover Lean enables the verification of formal mathematical proofs and is backed by an expanding community. Central to this ecosystem is its mathematical library, mathlib4, which lays the groundwork for the formalization of an expanding range of mathematical theories. However, searching for theorems in mathlib4 can be challenging. To successfully search in mathlib4, users often need to be familiar with its naming conventions or documentation strings. Therefore, creating a semantic search engine that can be used easily by individuals with varying familiarity with mathlib4 is very important. In this paper, we present a semantic search engine (https://leansearch.net/) for mathlib4 that accepts informal queries and finds the relevant theorems. We also establish a benchmark for assessing the performance of various search engines for mathlib4.
