Search

Search papers and lessons

Premise Selection

Level 4 · 10 min read

Premise selection picks, from a large library of proven facts, the few that an automated prover needs for a new goal, so the search does not drown in irrelevant lemmas.

On this page

  • Colour = topic mix
  • Probability
  • Neural network basics
  • Calculus
  • Discrete math
  • Linear algebra
  • Architectures
  • ReadReady to readNot yet

TL;DR

Premise selection chooses, from a large library of already proven facts, the few that a proof search needs for a new goal. A modern prover that tried every fact in a big library would waste its time and often get lost, so a ranking step first proposes a short list of candidates. The quality of that list often decides whether the prover finds the proof at all.

Builds on: Bi-Encoder, Logistic Regression · Leads to: LeanDojo, GPT-f

Where it's used

Formal mathematics libraries. The Mizar project, begun in the early 1970s, built a large library of formally checked mathematics. A new theorem in that library can rely on many earlier results, and a proof checker must be told which ones to use. Choosing them by hand was the usual method.

Lean and Mathlib. Lean is a proof assistant, a programming language in which every step of a proof is checked by the computer. Its community library, Mathlib, holds a very large body of formalised mathematics. A user who types a new goal wants the system to suggest the lemmas that help, and the same ranking is used by automatic provers that work through the library.

Language-model provers. Systems such as GPT-f train a language model to write proof steps, and more recent systems such as LeanDojo pair a language model with a retrieval step. In those systems premise selection is the retrieval part: the model is shown the goal and a shortlist of premises, and it writes the next step using them. The quality of the shortlist sets the upper limit on what the model can prove.

How it works

We need a tiny library to trace the steps. The new goal has an embedding q\mathbf{q}, and the library has three proven facts, each with its own embedding. Every vector has length 1, so the similarity between two of them is just their dot product.

Let q=(1,0)\mathbf{q} = (1, 0), and the three facts be L1=(0.6,0.8)L_1 = (0.6, 0.8), L2=(0,1)L_2 = (0, 1) and L3=(0.8,0.6)L_3 = (0.8, 0.6).

  1. Embed the goal and the facts. Each statement is turned into a vector ahead of time, and the library's vectors are stored. Check: each vector has length 1, since 0.62+0.82=10.6^2 + 0.8^2 = 1.
  2. Score each fact against the goal. The score is the dot product: q⋅L1=0.6\mathbf{q} \cdot L_1 = 0.6, q⋅L2=0\mathbf{q} \cdot L_2 = 0 and q⋅L3=0.8\mathbf{q} \cdot L_3 = 0.8. Check: q⋅L2=1×0+0×1=0\mathbf{q} \cdot L_2 = 1 \times 0 + 0 \times 1 = 0.
  3. Keep the top two. Sorting the scores gives L3L_3 first (0.8) and L1L_1 second (0.6). The shortlist is L3L_3 and L1L_1, and L2L_2 is left out. Check: the shortlist has two items, the number asked for.
  4. Hand the shortlist to the prover. The prover now searches using only the two facts. If it fails, the system can widen the list to three. Check: the search space shrank from three facts to two.

The same idea works for a library of a million facts. The embeddings are computed once, and each new goal costs one embedding and one fast nearest-neighbour lookup.

flowchart LR
  A[New goal] --> B[Embed the goal]
  B --> C[Score every stored fact]
  C --> D[Keep the top k]
  D --> E[Prover searches with the shortlist]
  E -->|fails| D

The math

A premise is a fact in the library that a proof might use. A goal is the statement to prove. Premise selection is a ranking problem: given a goal gg and a library L\mathcal{L}, return the kk premises that are most likely to be useful.

Step 2 in symbols: the score

If each goal and each premise is embedded as a vector, the score in the example is the cosine similarity of the two vectors. With unit-length vectors this is the dot product:

s(g,p)=cos⁡(ug,vp)=ug⋅vp∥ug∥ ∥vp∥.s(g, p) = \cos(\mathbf{u}_g, \mathbf{v}_p) = \frac{\mathbf{u}_g \cdot \mathbf{v}_p}{\lVert \mathbf{u}_g \rVert \, \lVert \mathbf{v}_p \rVert}.

The vectors ug\mathbf{u}_g and vp\mathbf{v}_p come from a Bi-Encoder, which embeds the goal and the premise separately. Because the premise embeddings do not depend on the goal, they can all be stored before any proof begins.

Step 3 in symbols: the shortlist

The shortlist is the set of the kk premises with the largest scores:

Top⁡k(g)=top⁡k{ s(g,p):p∈L }.\operatorname{Top}_k(g) = \operatorname{top}_k \bigl\{\, s(g, p) : p \in \mathcal{L} \,\bigr\}.

A learned alternative: the logistic score

Similarity is not always what makes a fact useful. A lemma can help a proof while looking nothing like the goal. A learned score can fix this. Give each pair of goal and premise a feature vector ϕ(g,p)\phi(g, p), such as the number of shared symbols, and score it with Logistic Regression:

P(useful∣g,p)=σ(w⊤ϕ(g,p)+b),σ(z)=11+e−z.P(\text{useful} \mid g, p) = \sigma\bigl(\mathbf{w}^{\top} \phi(g, p) + b\bigr), \qquad \sigma(z) = \frac{1}{1 + e^{-z}}.

The function σ\sigma is the sigmoid, which turns any number into a value between 0 and 1. The weights w\mathbf{w} and the bias bb are fitted on past proofs, where each useful premise is a positive example and each unhelpful one is a negative example.

The measure of success: recall at k

Recall at kk is the fraction of the useful premises that appear in the shortlist:

Recall@k=∣Top⁡k(g)∩Ug∣∣Ug∣,\text{Recall@}k = \frac{\lvert \operatorname{Top}_k(g) \cap U_g \rvert}{\lvert U_g \rvert},

where UgU_g is the set of premises that a known proof of the goal used. A prover can only use the premises it is given, so recall is the number to push up.

Worked examples

Example
1. The tiny library from the walkthrough

Let q=(1,0)\mathbf{q} = (1, 0), L1=(0.6,0.8)L_1 = (0.6, 0.8), L2=(0,1)L_2 = (0, 1) and L3=(0.8,0.6)L_3 = (0.8, 0.6). Find the top two by dot product.

  1. Score of L1L_1: 1×0.6+0×0.8=0.61 \times 0.6 + 0 \times 0.8 = 0.6.
  2. Score of L2L_2: 1×0+0×1=01 \times 0 + 0 \times 1 = 0.
  3. Score of L3L_3: 1×0.8+0×0.6=0.81 \times 0.8 + 0 \times 0.6 = 0.8.
  4. Sort: 0.80.8 (L3L_3), 0.60.6 (L1L_1), 00 (L2L_2).
  5. Top two: L3L_3 and L1L_1.

Interpretation: the fact that points in the most similar direction to the goal wins, and L2L_2, which is perpendicular to the goal, is the least similar.

Example
2. The standard case: a logistic score with one feature

Use one feature, the number of symbols that the goal and the premise share, with weight w=2w = 2 and bias b=−3b = -3. This is illustrative, not fitted to data.

  1. Premise A shares 1 symbol. Then z=2×1−3=−1z = 2 \times 1 - 3 = -1.
  2. σ(−1)=11+e1=11+2.718≈0.269\sigma(-1) = \dfrac{1}{1 + e^{1}} = \dfrac{1}{1 + 2.718} \approx 0.269.
  3. Premise B shares 2 symbols. Then z=2×2−3=1z = 2 \times 2 - 3 = 1.
  4. σ(1)=11+e−1=11+0.368≈0.731\sigma(1) = \dfrac{1}{1 + e^{-1}} = \dfrac{1}{1 + 0.368} \approx 0.731.
  5. Check: the two scores are z=−1z = -1 and z=1z = 1, mirror images around 0, so their probabilities are mirror images around 0.5 and add to 1. The ordering is what matters: premise B is more likely to be useful.

Interpretation: more shared symbols raise the score, and the sigmoid turns the score into a probability that a prover can rank.

Example
3. Realistic: how many useful premises does the shortlist catch?

A goal needs 3 premises from the library, and the proof is known. The ranker's shortlist of the top 10 contains 2 of them, and the top 40 contains all 3. This is illustrative.

  1. Recall@10 =2/3≈0.67= 2 / 3 \approx 0.67.
  2. Recall@40 =3/3=1.0= 3 / 3 = 1.0.
  3. The prover given the top 10 finds 2 of the 3 premises it needs, so it can still fail. Given the top 40, it has everything the proof uses, but it must search through 40 facts.
  4. Interpretation: a larger shortlist raises recall and makes the search harder, so the best kk is a balance between the two.

Try it. A goal needs 4 premises, and the top 16 contains 3 of them. What is Recall@16? Answer: 3/4=0.753 / 4 = 0.75.

Common mistakes and tradeoffs

It is tempting to think premise selection just finds the facts most similar to the goal. In fact a useful lemma often has a different shape from the goal, such as a general rule that the proof applies to a special case. Similarity finds the obvious neighbours, and a learned score can find the rest.

It is tempting to think a bigger shortlist is always safer. In fact each extra premise adds to the search, and a prover can be led astray by a plausible but useless fact. Recall goes up with kk, but the cost goes up too, so kk has to be tuned.

It is tempting to think that high recall of single premises is enough. In fact a proof needs a set of premises that work together, and a ranker that picks many similar facts can miss a fact that is needed but looks different.

ApproachStrengthWeakness
Keyword or symbol matchingSimple, fast, easy to explainMisses useful facts with different wording
Bi-Encoder embeddingsOne lookup per goal after pre-computing; scales to large librariesCompares goal and premise separately, so it cannot see their interaction
Cross-Encoder scoringReads goal and premise together; more accurateOne model pass per pair, too slow for a full library

Use a bi-encoder to narrow a large library to a few hundred candidates, then a more careful scorer to rank them. Use keyword matching only when the library is small or the wording is very uniform.

History

Mizar, begun in the early 1970s, was one of the first systems to hold a large library of formally checked mathematics, and its users depended on finding earlier results by name, by index and by hand. In the mid-2010s researchers began to train classifiers on past proofs to suggest which earlier facts a proof would use, and kernel methods and other classical learners were among the first tried.

Neural language models changed the field after 2020. GPT-f, from OpenAI, showed that a language model trained on formal proofs could write useful proof steps. Later systems, including LeanDojo in 2023, paired a language model with a retrieval step, so that premise selection became part of the system rather than a separate pre-processing stage. The idea caught on because the library grows over time, and a retrieval step keeps the prover working on a library of any size.

Recap

  • Premise selection shortlists the facts a prover needs from a large library.
  • A bi-encoder scores each fact by the cosine similarity of its embedding with the goal's embedding, so the library can be pre-computed.
  • A learned score with Logistic Regression and the sigmoid can find useful facts that do not look like the goal.
  • Recall at kk measures how many of the needed facts the shortlist catches, and kk trades recall against search cost.
  • Read next: LeanDojo, which pairs premise retrieval with a language-model prover, and GPT-f, which shows a language model writing proof steps.

Check yourself

QuestionRecall: why can a bi-encoder pre-compute the premise embeddings, but not a cross-encoder?Show answer

A Bi-Encoder embeds the goal and each premise separately, so each premise's vector does not depend on the goal and can be stored in advance. A Cross-Encoder reads the goal and the premise together in one pass, so its score must be computed fresh for every goal-premise pair.

QuestionComputation: the goal vector is q=(0,1)\mathbf{q} = (0, 1). A premise has vector (0.6,0.8)(0.6, 0.8). What is its cosine similarity with the goal?Show answer

Both vectors have length 1, so the cosine similarity is the dot product: 0×0.6+1×0.8=0.80 \times 0.6 + 1 \times 0.8 = 0.8.

QuestionWhy: why does a shortlist that ranks by similarity alone sometimes miss the lemma a proof needs?Show answer

A useful lemma can be a general rule whose statement looks nothing like the goal, for example one that is applied to a special case in the proof. Similarity favours facts with overlapping wording, so such a lemma can score low even though the proof needs it. A learned score trained on past proofs can learn to rank those facts higher.

QuestionApplied: a team's prover succeeds on 80 percent of goals when given the top 5 premises, and on 83 percent when given the top 50. The top 50 makes each proof attempt take ten times as long. What should they do?Show answer

The extra 3 percentage points cost ten times the compute, so the top 5 is the better default. They could check which goals gain from the larger list and give those more premises, or improve the ranker so that the top 5 already contains what the larger list adds. Improving the ranker is usually a better use of effort than raising kk.

Sources