Compare commits

...

12 Commits

Author SHA1 Message Date
Kim Morrison
cfc7a414c7 merge master 2025-10-31 05:41:43 +01:00
Kim Morrison
40d3af596e Merge branch 'library_suggestions' into suggestion_combinators 2025-10-31 05:15:40 +01:00
Kim Morrison
914077ae23 fix test 2025-10-31 05:01:12 +01:00
Kim Morrison
3bd8deeaa7 Merge branch 'library_suggestions' into suggestion_combinators 2025-10-31 04:45:50 +01:00
Kim Morrison
d5bdad83bd merge 2025-10-31 04:44:56 +01:00
Kim Morrison
d89027a2c6 fix 2025-10-31 04:44:17 +01:00
Kim Morrison
de1f4dbdcd Merge branch 'master' into library_suggestions 2025-10-31 04:42:16 +01:00
Kim Morrison
e2e54a5d6a Merge branch 'library_suggestions' into suggestion_combinators 2025-10-31 03:40:30 +01:00
Kim Morrison
8795c08b15 fix tests, rename 2025-10-31 03:39:57 +01:00
Kim Morrison
cb3dedca5a feat: library suggestion engine for local theorems 2025-10-31 03:37:10 +01:00
Kim Morrison
1b57b9f883 feat: library suggestion engine for local theorems 2025-10-31 03:37:02 +01:00
Kim Morrison
bc683529c1 chore: use 'library suggestions' rather than 'premise selection' 2025-10-31 02:57:42 +01:00
2 changed files with 55 additions and 0 deletions

View File

@@ -286,6 +286,22 @@ def random (gen : StdGen := ⟨37, 59⟩) : Selector := fun _ cfg => do
suggestions := suggestions.push { name := name, score := 1.0 / consts.size.toFloat }
return suggestions
/-- A library suggestion engine that returns locally defined theorems (those in the current file). -/
def currentFile : Selector := fun _ cfg => do
let env getEnv
let max := cfg.maxSuggestions
-- Use map₂ from the staged map, which contains locally defined constants
let mut suggestions := #[]
for (name, ci) in env.constants.map₂.toList do
if suggestions.size >= max then
break
if isDeniedPremise env name then
continue
match ci with
| .thmInfo _ => suggestions := suggestions.push { name := name, score := 1.0 }
| _ => continue
return suggestions
builtin_initialize librarySuggestionsExt : EnvExtension (Option Selector)
registerEnvExtension (pure none)

View File

@@ -0,0 +1,39 @@
import Lean.LibrarySuggestions.Basic
-- Define some initial local constants
def myLocalDef : Nat := 42
theorem myLocalTheorem : myLocalDef = 42 := rfl
-- Add a theorem in the Lean namespace (should be filtered by isDeniedPremise)
namespace Lean
theorem shouldBeFiltered : True := trivial
end Lean
-- Test the currentFile selector (should only show theorems, not definitions)
set_library_suggestions Lean.LibrarySuggestions.currentFile
-- First test: should show only myLocalTheorem
-- (not myLocalDef since it's a def, not Lean.shouldBeFiltered since it's in Lean namespace)
/--
info: Library suggestions: [myLocalTheorem]
-/
#guard_msgs in
example : True := by
suggestions
trivial
-- Add more local constants (mix of theorems and definitions)
theorem anotherTheorem : True := trivial
def myFunction (x : Nat) : Nat := x + 1
-- Second test: should show only the two theorems (not myFunction)
/--
info: Library suggestions: [anotherTheorem, myLocalTheorem]
-/
#guard_msgs in
example : False True := by
suggestions
intro h
trivial