Skip to content

Commit c21c11f

Browse files
committed
chore: exact? runs nonspecific lemmas too (#8459)
Previously, `exact?` has only indexed lemmas with a "specific" `DiscrTree` key (this meant: anything except `#[star]` or `#[Eq, star, star, star]`). This means that it wouldn't apply some very general lemmas, e.g. `le_antisymm`. The performance improvement here is pretty minor: the `DiscrTree` returns the more specific matches first, so we only attempt to apply the nonspecific keys last (i.e. if we would otherwise have already failed). Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
1 parent 01a486f commit c21c11f

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

Mathlib/Tactic/LibrarySearch.lean

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,6 @@ def processLemma (name : Name) (constInfo : ConstantInfo) :
6464
|>.push (← DiscrTree.mkPath lhs discrTreeConfig, (name, .mpr))
6565
| _ => return r
6666

67-
/-- Insert a lemma into the discrimination tree. -/
68-
-- Recall that `apply?` caches the discrimination tree on disk.
69-
-- If you are modifying this file, you will probably want to delete
70-
-- `.lake/build/lib/MathlibExtras/LibrarySearch.extra`
71-
-- so that the cache is rebuilt.
72-
def addLemma (name : Name) (constInfo : ConstantInfo)
73-
(lemmas : DiscrTree (Name × DeclMod)) : MetaM (DiscrTree (Name × DeclMod)) := do
74-
let mut lemmas := lemmas
75-
for (key, value) in ← processLemma name constInfo do
76-
lemmas := lemmas.insertIfSpecific key value discrTreeConfig
77-
return lemmas
78-
7967
/-- Construct the discrimination tree of all lemmas. -/
8068
def buildDiscrTree : IO (DiscrTreeCache (Name × DeclMod)) :=
8169
DiscrTreeCache.mk "apply?: init cache" processLemma

test/LibrarySearch/basic.lean

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Mathlib.Util.AssertNoSorry
33
import Mathlib.Algebra.Order.Ring.Canonical
44
import Mathlib.Data.Quot
55
import Mathlib.Data.Nat.Prime
6+
import Mathlib.Data.Real.Basic
67

78
set_option autoImplicit true
89

@@ -222,7 +223,10 @@ lemma prime_of_prime (n : ℕ) : Prime n ↔ Nat.Prime n := by
222223
lemma ex' (x : ℕ) (_h₁ : x = 0) (h : 2 * 2 ∣ x) : 2 ∣ x := by
223224
exact? says exact dvd_of_mul_left_dvd h
224225

226+
-- Example from https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Exact.3F.20fails.20on.20le_antisymm/near/388993167
227+
example {x y : ℝ} (hxy : x ≤ y) (hyx : y ≤ x) : x = y := by
228+
exact? says exact le_antisymm hxy hyx
229+
225230
-- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/apply.3F.20failure/near/402534407
226-
#guard_msgs in
227231
example (P Q : Prop) (h : P → Q) (h' : ¬Q) : ¬P := by
228232
exact? says exact mt h h'

0 commit comments

Comments
 (0)