Skip to content

Commit 38ca310

Browse files
authored
feat: @[grind] annotations for TreeMap (#8446)
This PR adds basic `@[grind]` annotations for `TreeMap` and its variants. Likely more annotations will be added after we've explored some examples.
1 parent 3dd12f8 commit 38ca310

File tree

19 files changed

+974
-709
lines changed

19 files changed

+974
-709
lines changed

src/Init/Data/Array/Lemmas.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2797,7 +2797,7 @@ theorem reverse_eq_iff {xs ys : Array α} : xs.reverse = ys ↔ xs = ys.reverse
27972797
cases xs
27982798
simp
27992799

2800-
@[grind _=_]theorem filterMap_reverse {f : α → Option β} {xs : Array α} : (xs.reverse.filterMap f) = (xs.filterMap f).reverse := by
2800+
@[grind _=_] theorem filterMap_reverse {f : α → Option β} {xs : Array α} : (xs.reverse.filterMap f) = (xs.filterMap f).reverse := by
28012801
cases xs
28022802
simp
28032803

@@ -3526,7 +3526,7 @@ theorem foldrM_append [Monad m] [LawfulMonad m] {f : α → β → m β} {b} {xs
35263526
(xs ++ ys).foldr f b start 0 = xs.foldr f (ys.foldr f b) :=
35273527
foldrM_append' w
35283528

3529-
@[grind _=_]theorem foldl_append {β : Type _} {f : β → α → β} {b} {xs ys : Array α} :
3529+
@[grind _=_] theorem foldl_append {β : Type _} {f : β → α → β} {b} {xs ys : Array α} :
35303530
(xs ++ ys).foldl f b = ys.foldl f (xs.foldl f b) :=
35313531
foldlM_append
35323532

@@ -3782,7 +3782,7 @@ theorem contains_iff_exists_mem_beq [BEq α] {xs : Array α} {a : α} :
37823782
rcases xs with ⟨xs⟩
37833783
simp [List.contains_iff_exists_mem_beq]
37843784

3785-
@[grind]
3785+
@[grind _=_]
37863786
theorem contains_iff_mem [BEq α] [LawfulBEq α] {xs : Array α} {a : α} :
37873787
xs.contains a ↔ a ∈ xs := by
37883788
simp

src/Init/Data/List/Lemmas.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2952,7 +2952,7 @@ theorem contains_iff_exists_mem_beq [BEq α] {l : List α} {a : α} :
29522952
l.contains a ↔ ∃ a' ∈ l, a == a' := by
29532953
induction l <;> simp_all
29542954

2955-
@[grind]
2955+
@[grind _=_]
29562956
theorem contains_iff_mem [BEq α] [LawfulBEq α] {l : List α} {a : α} :
29572957
l.contains a ↔ a ∈ l := by
29582958
simp

src/Init/Data/List/Nat/TakeDrop.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ theorem getElem?_take_eq_none {l : List α} {i j : Nat} (h : i ≤ j) :
5656
(l.take i)[j]? = none :=
5757
getElem?_eq_none <| Nat.le_trans (length_take_le _ _) h
5858

59-
@[grind =]theorem getElem?_take {l : List α} {i j : Nat} :
59+
@[grind =] theorem getElem?_take {l : List α} {i j : Nat} :
6060
(l.take i)[j]? = if j < i then l[j]? else none := by
6161
split
6262
· next h => exact getElem?_take_of_lt h

src/Init/Data/Vector/Lemmas.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,7 @@ abbrev forall_mem_mkVector := @forall_mem_replicate
21052105
@[deprecated getElem_replicate (since := "2025-03-18")]
21062106
abbrev getElem_mkVector := @getElem_replicate
21072107

2108-
@[grind]theorem getElem?_replicate {a : α} {n i : Nat} : (replicate n a)[i]? = if i < n then some a else none := by
2108+
@[grind] theorem getElem?_replicate {a : α} {n i : Nat} : (replicate n a)[i]? = if i < n then some a else none := by
21092109
simp [getElem?_def]
21102110

21112111
@[deprecated getElem?_replicate (since := "2025-03-18")]
@@ -2685,7 +2685,7 @@ theorem contains_iff_exists_mem_beq [BEq α] {xs : Vector α n} {a : α} :
26852685
rcases xs with ⟨xs, rfl⟩
26862686
simp [Array.contains_iff_exists_mem_beq]
26872687

2688-
@[grind]
2688+
@[grind _=_]
26892689
theorem contains_iff_mem [BEq α] [LawfulBEq α] {xs : Vector α n} {a : α} :
26902690
xs.contains a ↔ a ∈ xs := by
26912691
simp

src/Std/Data/DHashMap/Lemmas.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ theorem mem_iff_contains {a : α} : a ∈ m ↔ m.contains a :=
5151

5252
-- While setting up the API, often use this in the reverse direction,
5353
-- but prefer this direction for users.
54-
@[simp, grind]
54+
@[simp, grind _=_]
5555
theorem contains_iff_mem {a : α} : m.contains a ↔ a ∈ m :=
5656
Iff.rfl
5757

@@ -721,7 +721,7 @@ theorem contains_eq_isSome_getKey? [EquivBEq α] [LawfulHashable α] {a : α} :
721721
m.contains a = (m.getKey? a).isSome :=
722722
Raw₀.contains_eq_isSome_getKey? ⟨m.1, _⟩ m.2
723723

724-
@[simp]
724+
@[simp, grind =]
725725
theorem isSome_getKey?_eq_contains [EquivBEq α] [LawfulHashable α] {a : α} :
726726
(m.getKey? a).isSome = m.contains a :=
727727
contains_eq_isSome_getKey?.symm

src/Std/Data/DHashMap/RawLemmas.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ theorem isEmpty_insert [EquivBEq α] [LawfulHashable α] (h : m.WF) {k : α} {v
102102
theorem mem_iff_contains {m : Raw α β} {a : α} :
103103
a ∈ m ↔ m.contains a := Iff.rfl
104104

105-
@[simp, grind]
105+
@[simp, grind _=_]
106106
theorem contains_iff_mem {m : Raw α β} {a : α} :
107107
m.contains a ↔ a ∈ m := Iff.rfl
108108

@@ -779,7 +779,7 @@ theorem contains_eq_isSome_getKey? [EquivBEq α] [LawfulHashable α] (h : m.WF)
779779
m.contains a = (m.getKey? a).isSome := by
780780
simp_to_raw using Raw₀.contains_eq_isSome_getKey?
781781

782-
@[simp]
782+
@[simp, grind =]
783783
theorem isSome_getKey?_eq_contains [EquivBEq α] [LawfulHashable α] (h : m.WF) {a : α} :
784784
(m.getKey? a).isSome = m.contains a :=
785785
(contains_eq_isSome_getKey? h).symm

0 commit comments

Comments
 (0)