Skip to content

Commit 0db89d6

Browse files
authored
chore: use 'library suggestions' rather than 'premise selection' (#11029)
This PR changes the terminology used from "premise selection" to "library suggestions". This will be more understandable to users (we don't assume anyone is familiar with the premise selection literature), and avoids a conflict with the existing use of "premise" in Lean terminology (e.g. "major premise" in induction, as well as generally the synonym for "hypothesis"/"argument").
1 parent 00d41d6 commit 0db89d6

23 files changed

+171
-170
lines changed

src/Init/Grind/Config.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ structure Config where
1818
/-- If `lax` is `true`, `grind` will silently ignore any parameters referring to non-existent theorems
1919
or for which no patterns can be generated. -/
2020
lax : Bool := false
21-
/-- If `premises` is `true`, `grind` will invoke the currently configured premise selecor on the current goal,
22-
and add attempt to use the resulting suggestions as premises to the `grind` tactic. -/
23-
premises : Bool := false
21+
/-- If `suggestions` is `true`, `grind` will invoke the currently configured library suggestion engine on the current goal,
22+
and add attempt to use the resulting suggestions as additional parameters to the `grind` tactic. -/
23+
suggestions : Bool := false
2424
/-- Maximum number of case-splits in a proof search branch. It does not include splits performed during normalization. -/
2525
splits : Nat := 9
2626
/-- Maximum number of E-matching (aka heuristic theorem instantiation) rounds before each case split. -/

src/Init/Notation.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -863,12 +863,12 @@ syntax (name := infoTreesCmd)
863863
"#info_trees" " in" ppLine command : command
864864

865865
/--
866-
Specify a premise selection engine.
867-
Note that Lean does not ship a default premise selection engine,
866+
Specify a library suggestion engine.
867+
Note that Lean does not ship a default library suggestion engine,
868868
so this is only useful in conjunction with a downstream package which provides one.
869869
-/
870-
syntax (name := setPremiseSelectorCmd)
871-
"set_premise_selector" term : command
870+
syntax (name := setLibrarySuggestionsCmd)
871+
"set_library_suggestions" term : command
872872

873873
namespace Parser
874874

src/Init/Tactics.lean

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,11 +1759,12 @@ as well as tactics such as `next`, `case`, and `rename_i`.
17591759
syntax (name := exposeNames) "expose_names" : tactic
17601760

17611761
/--
1762-
`#suggest_premises` will suggest premises for the current goal, using the currently registered premise selector.
1762+
`#suggestions` will suggest relevant theorems from the library for the current goal,
1763+
using the currently registered library suggestion engine.
17631764
17641765
The suggestions are printed in the order of their confidence, from highest to lowest.
17651766
-/
1766-
syntax (name := suggestPremises) "suggest_premises" : tactic
1767+
syntax (name := suggestions) "suggestions" : tactic
17671768

17681769
/--
17691770
Close fixed-width `BitVec` and `Bool` goals by obtaining a proof from an external SAT solver and

src/Lean.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public import Lean.LabelAttribute
4040
public import Lean.AddDecl
4141
public import Lean.Replay
4242
public import Lean.PrivateName
43-
public import Lean.PremiseSelection
43+
public import Lean.LibrarySuggestions
4444
public import Lean.Namespace
4545
public import Lean.EnvExtension
4646
public import Lean.ErrorExplanation

src/Lean/Elab/Tactic/Grind/Main.lean

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public import Lean.Meta.Tactic.Grind.Main
99
public import Lean.Meta.Tactic.TryThis
1010
public import Lean.Elab.Command
1111
public import Lean.Elab.Tactic.Config
12-
public import Lean.PremiseSelection.Basic
12+
public import Lean.LibrarySuggestions.Basic
1313
import Lean.Meta.Tactic.Grind.SimpUtil
1414
import Lean.Meta.Tactic.Grind.EMatchTheoremParam
1515
import Lean.Elab.Tactic.Grind.Basic
@@ -77,35 +77,35 @@ private def parseModifier (s : String) : CoreM Grind.AttrKind := do
7777
| .ok stx => Grind.getAttrKindCore stx
7878
| _ => throwError "unexpected modifier {s}"
7979

80-
open PremiseSelection in
81-
def elabGrindPremises
82-
(params : Grind.Params) (premises : Array Suggestion := #[]) : MetaM Grind.Params := do
80+
open LibrarySuggestions in
81+
def elabGrindSuggestions
82+
(params : Grind.Params) (suggestions : Array Suggestion := #[]) : MetaM Grind.Params := do
8383
let mut params := params
84-
for p in premises do
84+
for p in suggestions do
8585
let attr ← match p.flag with
8686
| some flag => parseModifier flag
8787
| none => pure <| .ematch (.default false)
8888
match attr with
8989
| .ematch kind =>
9090
try
9191
params ← addEMatchTheorem params (mkIdent p.name) p.name kind false (warn := false)
92-
catch _ => pure () -- Don't worry if premise suggestion gave bad suggestions.
92+
catch _ => pure () -- Don't worry if library suggestions gave bad theorems.
9393
| _ =>
9494
-- We could actually support arbitrary grind modifiers,
9595
-- and call `processParam` rather than `addEMatchTheorem`,
9696
-- but this would require a larger refactor.
97-
-- Let's only do this if there is a prospect of a premise selector supporting this.
97+
-- Let's only do this if there is a prospect of a library suggestion engine supporting this.
9898
throwError "unexpected modifier {p.flag}"
9999
return params
100100

101-
open PremiseSelection in
102-
def elabGrindParamsAndPremises
101+
open LibrarySuggestions in
102+
def elabGrindParamsAndSuggestions
103103
(params : Grind.Params)
104104
(ps : TSyntaxArray ``Parser.Tactic.grindParam)
105-
(premises : Array Suggestion := #[])
105+
(suggestions : Array Suggestion := #[])
106106
(only : Bool) (lax : Bool := false) : MetaM Grind.Params := do
107107
let params ← elabGrindParams params ps (lax := lax) (only := only)
108-
elabGrindPremises params premises
108+
elabGrindSuggestions params suggestions
109109

110110
def mkGrindParams
111111
(config : Grind.Config) (only : Bool) (ps : TSyntaxArray ``Parser.Tactic.grindParam) (mvarId : MVarId) :
@@ -119,12 +119,11 @@ def mkGrindParams
119119
-/
120120
let casesTypes ← Grind.getCasesTypes
121121
let params := { params with ematch, casesTypes, inj }
122-
let premises ← if config.premises then
123-
let suggestions ← PremiseSelection.select mvarId
124-
pure suggestions
122+
let suggestions ← if config.suggestions then
123+
LibrarySuggestions.select mvarId
125124
else
126125
pure #[]
127-
let params ← elabGrindParamsAndPremises params ps premises (only := only) (lax := config.lax)
126+
let params ← elabGrindParamsAndSuggestions params ps suggestions (only := only) (lax := config.lax)
128127
trace[grind.debug.inj] "{params.inj.getOrigins.map (·.pp)}"
129128
return params
130129

@@ -201,16 +200,16 @@ def setGrindParams (stx : TSyntax `tactic) (params : Array Syntax) : TSyntax `ta
201200
def getGrindParams (stx : TSyntax `tactic) : Array Syntax :=
202201
stx.raw[grindParamsPos][1].getSepArgs
203202

204-
/-- Filter out `+premises` from the config syntax -/
205-
def filterPremisesFromConfig (config : TSyntax ``Lean.Parser.Tactic.optConfig) : TSyntax ``Lean.Parser.Tactic.optConfig :=
203+
/-- Filter out `+suggestions` from the config syntax -/
204+
def filterSuggestionsFromConfig (config : TSyntax ``Lean.Parser.Tactic.optConfig) : TSyntax ``Lean.Parser.Tactic.optConfig :=
206205
let configItems := config.raw.getArgs
207206
let filteredItems := configItems.filter fun item =>
208-
-- Keep all items except +premises
207+
-- Keep all items except +suggestions
209208
-- Structure: null node -> configItem -> posConfigItem -> ["+", ident]
210209
match item[0]? with
211210
| some configItem => match configItem[0]? with
212211
| some posConfigItem => match posConfigItem[1]? with
213-
| some ident => !(posConfigItem.getKind == ``Lean.Parser.Tactic.posConfigItem && ident.getId == `premises)
212+
| some ident => !(posConfigItem.getKind == ``Lean.Parser.Tactic.posConfigItem && ident.getId == `suggestions)
214213
| none => true
215214
| none => true
216215
| none => true
@@ -232,7 +231,7 @@ def mkGrindOnly
232231
else
233232
let param ← Grind.globalDeclToGrindParamSyntax declName kind minIndexable
234233
params := params.push param
235-
let filteredConfig := filterPremisesFromConfig config
234+
let filteredConfig := filterSuggestionsFromConfig config
236235
let result ← `(tactic| grind $filteredConfig:optConfig only)
237236
return setGrindParams result params
238237

src/Lean/Elab/Tactic/Try.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ private def mkTryEvalSuggestStx (info : Try.Info) : MetaM (TSyntax `tactic) := d
673673

674674
-- TODO: vanilla `induction`.
675675
-- TODO: make it extensible.
676-
-- TODO: premise selection.
676+
-- TODO: library suggestions.
677677

678678
@[builtin_tactic Lean.Parser.Tactic.tryTrace] def evalTryTrace : Tactic := fun stx => do
679679
match stx with
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Authors: Kim Morrison
66
module
77

88
prelude
9-
import Lean.PremiseSelection.Basic
10-
import Lean.PremiseSelection.SymbolFrequency
11-
import Lean.PremiseSelection.MePo
12-
import Lean.PremiseSelection.SineQuaNon
9+
import Lean.LibrarySuggestions.Basic
10+
import Lean.LibrarySuggestions.SymbolFrequency
11+
import Lean.LibrarySuggestions.MePo
12+
import Lean.LibrarySuggestions.SineQuaNon
Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,20 @@ public import Lean.Meta.CompletionName
1212
public import Init.Data.Random
1313

1414
/-!
15-
# An API for premise selection algorithms.
15+
# An API for library suggestion algorithms.
1616
17-
This module provides a basic API for premise selection algorithms,
18-
which are used to suggest identifiers that should be introduced in a proof.
17+
This module provides a basic API for library suggestion algorithms,
18+
which are used to suggest relevant theorems from the library for the current goal.
19+
In the literature this is usually known as "premise selection",
20+
but we mostly avoid that term as most of our users will not be familiar with the term.
1921
2022
The core interface is the `Selector` type, which is a function from a metavariable
2123
and a configuration to a list of suggestions.
24+
The `Selector` is registered as an environment extension,
25+
and the trivial (no suggestions) implementation is `Lean.LibrarySuggestions.empty`.
2226
23-
The `Selector` is registered as an environment extension, and the trivial (no suggestions) implementation
24-
is `Lean.PremiseSelection.empty`.
25-
26-
Lean does not provide a default premise selector, so this module is intended to be used in conjunction
27-
with a downstream package which registers a premise selector.
27+
Lean does not provide a default library suggestion engine, so this module is intended to be used in conjunction
28+
with a downstream package which registers a library suggestion engine.
2829
-/
2930

3031
namespace Lean.Expr.FoldRelevantConstantsImpl
@@ -113,7 +114,7 @@ public def Lean.MVarId.getRelevantConstants (g : MVarId) : MetaM NameSet := with
113114

114115
@[expose] public section
115116

116-
namespace Lean.PremiseSelection
117+
namespace Lean.LibrarySuggestions
117118

118119
/--
119120
A `Suggestion` is essentially just an identifier and a confidence score that the identifier is relevant.
@@ -285,52 +286,52 @@ def random (gen : StdGen := ⟨37, 59⟩) : Selector := fun _ cfg => do
285286
suggestions := suggestions.push { name := name, score := 1.0 / consts.size.toFloat }
286287
return suggestions
287288

288-
builtin_initialize premiseSelectorExt : EnvExtension (Option Selector) ←
289+
builtin_initialize librarySuggestionsExt : EnvExtension (Option Selector) ←
289290
registerEnvExtension (pure none)
290291

291-
/-- Generate premise suggestions for the given metavariable, using the currently registered premise selector. -/
292+
/-- Generate library suggestions for the given metavariable, using the currently registered library suggestions engine. -/
292293
def select (m : MVarId) (c : Config := {}) : MetaM (Array Suggestion) := do
293-
let some selector := premiseSelectorExt.getState (← getEnv) |
294-
throwError "No premise selector registered. \
295-
(Note that Lean does not provide a default premise selector, \
294+
let some selector := librarySuggestionsExt.getState (← getEnv) |
295+
throwError "No library suggestions engine registered. \
296+
(Note that Lean does not provide a default library suggestions engine, \
296297
these must be provided by a downstream library, \
297-
and configured using `set_premise_selector`.)"
298+
and configured using `set_library_suggestions`.)"
298299
selector m c
299300

300301
/-!
301302
Currently the registration mechanism is just global state.
302-
This means that if multiple modules register premise selectors,
303+
This means that if multiple modules register library suggestions engines,
303304
the behaviour will be dependent on the order of loading modules.
304305
305306
We should replace this with a mechanism so that
306-
premise selectors are configured via options in the `lakefile`, and
307+
library suggestions engines are configured via options in the `lakefile`, and
307308
commands are only used to override in a single declaration or file.
308309
-/
309310

310-
/-- Set the current premise selector.-/
311-
def registerPremiseSelector (selector : Selector) : CoreM Unit := do
312-
modifyEnv fun env => premiseSelectorExt.setState env (some selector)
311+
/-- Set the current library suggestions engine.-/
312+
def registerLibrarySuggestions (selector : Selector) : CoreM Unit := do
313+
modifyEnv fun env => librarySuggestionsExt.setState env (some selector)
313314

314315
open Lean Elab Command in
315-
@[builtin_command_elab setPremiseSelectorCmd, inherit_doc setPremiseSelectorCmd]
316-
def elabSetPremiseSelector : CommandElab
317-
| `(command| set_premise_selector $selector) => do
318-
if `Lean.PremiseSelection.Basic ∉ (← getEnv).header.moduleNames then
319-
logWarning "Add `import Lean.PremiseSelection.Basic` before using the `set_premise_selector` command."
316+
@[builtin_command_elab setLibrarySuggestionsCmd, inherit_doc setLibrarySuggestionsCmd]
317+
def elabSetLibrarySuggestions : CommandElab
318+
| `(command| set_library_suggestions $selector) => do
319+
if `Lean.LibrarySuggestions.Basic ∉ (← getEnv).header.moduleNames then
320+
logWarning "Add `import Lean.LibrarySuggestions.Basic` before using the `set_library_suggestions` command."
320321
let selector ← liftTermElabM do
321322
try
322323
let selectorTerm ← Term.elabTermEnsuringType selector (some (Expr.const ``Selector []))
323324
unsafe Meta.evalExpr Selector (Expr.const ``Selector []) selectorTerm
324325
catch _ =>
325326
throwError "Failed to elaborate {selector} as a `MVarId → Config → MetaM (Array Suggestion)`."
326-
liftCoreM (registerPremiseSelector selector)
327+
liftCoreM (registerLibrarySuggestions selector)
327328
| _ => throwUnsupportedSyntax
328329

329330
open Lean.Elab.Tactic in
330-
@[builtin_tactic Lean.Parser.Tactic.suggestPremises] def evalSuggestPremises : Tactic := fun _ =>
331+
@[builtin_tactic Lean.Parser.Tactic.suggestions] def evalSuggestions : Tactic := fun _ =>
331332
liftMetaTactic1 fun mvarId => do
332333
let suggestions ← select mvarId
333-
logInfo m!"Premise suggestions: {suggestions.map (·.name)}"
334+
logInfo m!"Library suggestions: {suggestions.map (·.name)}"
334335
return mvarId
335336

336-
end Lean.PremiseSelection
337+
end Lean.LibrarySuggestions
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Authors: Kim Morrison
66
module
77

88
prelude
9-
public import Lean.PremiseSelection.Basic
10-
import Lean.PremiseSelection.SymbolFrequency
9+
public import Lean.LibrarySuggestions.Basic
10+
import Lean.LibrarySuggestions.SymbolFrequency
1111
import Lean.Meta.Basic
1212

1313
/-!
@@ -21,7 +21,7 @@ It needs to be tuned and evaluated for Lean.
2121

2222
open Lean
2323

24-
namespace Lean.PremiseSelection.MePo
24+
namespace Lean.LibrarySuggestions.MePo
2525

2626
builtin_initialize registerTraceClass `mepo
2727

src/Lean/PremiseSelection/SineQuaNon.lean renamed to src/Lean/LibrarySuggestions/SineQuaNon.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ prelude
99
public import Lean.CoreM
1010
public import Lean.Meta.Basic
1111
import Lean.Meta.Instances
12-
import Lean.PremiseSelection.SymbolFrequency
13-
public import Lean.PremiseSelection.Basic
12+
import Lean.LibrarySuggestions.SymbolFrequency
13+
public import Lean.LibrarySuggestions.Basic
1414

1515
/-!
1616
# Sine Qua Non premise selection
@@ -21,7 +21,7 @@ This is an implementation of the "Sine Qua Non" premise selection algorithm, fro
2121
It needs to be tuned and evaluated for Lean.
2222
-/
2323

24-
namespace Lean.PremiseSelection.SineQuaNon
24+
namespace Lean.LibrarySuggestions.SineQuaNon
2525

2626
builtin_initialize registerTraceClass `sineQuaNon
2727

@@ -193,4 +193,4 @@ public def sineQuaNonSelector (depthFactor : Float := 1.5) : Selector := fun g c
193193
let suggestions ← sineQuaNon constants config.maxSuggestions depthFactor
194194
return suggestions.take config.maxSuggestions
195195

196-
end Lean.PremiseSelection
196+
end Lean.LibrarySuggestions

0 commit comments

Comments
 (0)