From 7adea80123ad7166d850f5192bbf2eb1e91460db Mon Sep 17 00:00:00 2001 From: Kim Morrison Date: Tue, 3 Jun 2025 14:13:01 +1000 Subject: [PATCH] chore: missing `[@grind] annotations for `List/Array.modify` (#8601) --- src/Init/Data/Array/Lemmas.lean | 14 +++++++------- src/Init/Data/List/Nat/Modify.lean | 9 ++++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Init/Data/Array/Lemmas.lean b/src/Init/Data/Array/Lemmas.lean index a9c63ccba0..71222d9fc3 100644 --- a/src/Init/Data/Array/Lemmas.lean +++ b/src/Init/Data/Array/Lemmas.lean @@ -4076,11 +4076,11 @@ abbrev all_mkArray := @all_replicate /-! ### modify -/ -@[simp] theorem size_modify {xs : Array α} {i : Nat} {f : α → α} : (xs.modify i f).size = xs.size := by +@[simp, grind =] theorem size_modify {xs : Array α} {i : Nat} {f : α → α} : (xs.modify i f).size = xs.size := by unfold modify modifyM split <;> simp -theorem getElem_modify {xs : Array α} {j i} (h : i < (xs.modify j f).size) : +@[grind =] theorem getElem_modify {xs : Array α} {j i} (h : i < (xs.modify j f).size) : (xs.modify j f)[i] = if j = i then f (xs[i]'(by simpa using h)) else xs[i]'(by simpa using h) := by simp only [modify, modifyM] split @@ -4088,7 +4088,7 @@ theorem getElem_modify {xs : Array α} {j i} (h : i < (xs.modify j f).size) : · simp only [Id.run_pure] rw [if_neg (mt (by rintro rfl; exact h) (by simp_all))] -@[simp] theorem toList_modify {xs : Array α} {f : α → α} {i : Nat} : +@[simp, grind =] theorem toList_modify {xs : Array α} {f : α → α} {i : Nat} : (xs.modify i f).toList = xs.toList.modify i f := by apply List.ext_getElem · simp @@ -4103,7 +4103,7 @@ theorem getElem_modify_of_ne {xs : Array α} {i : Nat} (h : i ≠ j) (xs.modify i f)[j] = xs[j]'(by simpa using hj) := by simp [getElem_modify hj, h] -theorem getElem?_modify {xs : Array α} {i : Nat} {f : α → α} {j : Nat} : +@[grind =] theorem getElem?_modify {xs : Array α} {i : Nat} {f : α → α} {j : Nat} : (xs.modify i f)[j]? = if i = j then xs[j]?.map f else xs[j]? := by simp only [getElem?_def, size_modify, getElem_modify, Option.map_dif] split <;> split <;> rfl @@ -4152,18 +4152,18 @@ theorem swap_comm {xs : Array α} {i j : Nat} (hi hj) : xs.swap i j hi hj = xs.s · split <;> simp_all · split <;> simp_all -@[simp] theorem size_swapIfInBounds {xs : Array α} {i j : Nat} : +@[simp, grind =] theorem size_swapIfInBounds {xs : Array α} {i j : Nat} : (xs.swapIfInBounds i j).size = xs.size := by unfold swapIfInBounds; split <;> (try split) <;> simp [size_swap] /-! ### swapAt -/ -@[simp] theorem swapAt_def {xs : Array α} {i : Nat} {v : α} (hi) : +@[simp, grind =] theorem swapAt_def {xs : Array α} {i : Nat} {v : α} (hi) : xs.swapAt i v hi = (xs[i], xs.set i v) := rfl theorem size_swapAt {xs : Array α} {i : Nat} {v : α} (hi) : (xs.swapAt i v hi).2.size = xs.size := by simp -@[simp] +@[simp, grind =] theorem swapAt!_def {xs : Array α} {i : Nat} {v : α} (h : i < xs.size) : xs.swapAt! i v = (xs[i], xs.set i v) := by simp [swapAt!, h] diff --git a/src/Init/Data/List/Nat/Modify.lean b/src/Init/Data/List/Nat/Modify.lean index 3ec310af81..640bd77254 100644 --- a/src/Init/Data/List/Nat/Modify.lean +++ b/src/Init/Data/List/Nat/Modify.lean @@ -156,7 +156,7 @@ theorem modifyHead_eq_modify_zero (f : α → α) (l : List α) : @[simp] theorem modify_eq_nil_iff {f : α → α} {i} {l : List α} : l.modify i f = [] ↔ l = [] := by cases l <;> cases i <;> simp -theorem getElem?_modify (f : α → α) : +@[grind =] theorem getElem?_modify (f : α → α) : ∀ i (l : List α) j, (l.modify i f)[j]? = (fun a => if i = j then f a else a) <$> l[j]? | n, l, 0 => by cases l <;> cases n <;> simp | n, [], _+1 => by cases n <;> rfl @@ -167,7 +167,7 @@ theorem getElem?_modify (f : α → α) : cases h' : l[j]? <;> by_cases h : i = j <;> simp [h, if_pos, if_neg, Option.map, mt Nat.succ.inj, not_false_iff, h'] -@[simp] theorem length_modify (f : α → α) : ∀ (l : List α) i, (l.modify i f).length = l.length := +@[simp, grind =] theorem length_modify (f : α → α) : ∀ (l : List α) i, (l.modify i f).length = l.length := length_modifyTailIdx _ fun l => by cases l <;> rfl @[simp] theorem getElem?_modify_eq (f : α → α) (i) (l : List α) : @@ -178,7 +178,7 @@ theorem getElem?_modify (f : α → α) : (l.modify i f)[j]? = l[j]? := by simp only [getElem?_modify, if_neg h, id_map'] -theorem getElem_modify (f : α → α) (i) (l : List α) (j) (h : j < (l.modify i f).length) : +@[grind =] theorem getElem_modify (f : α → α) (i) (l : List α) (j) (h : j < (l.modify i f).length) : (l.modify i f)[j] = if i = j then f (l[j]'(by simp at h; omega)) else l[j]'(by simp at h; omega) := by rw [getElem_eq_iff, getElem?_modify] @@ -245,6 +245,7 @@ theorem exists_of_modify (f : α → α) {i} {l : List α} (h : i < l.length) : @[simp] theorem modify_id (i) (l : List α) : l.modify i id = l := by simp [modify] +@[grind =] theorem take_modify (f : α → α) (i j) (l : List α) : (l.modify i f).take j = (l.take j).modify i f := by induction j generalizing l i with @@ -257,6 +258,7 @@ theorem take_modify (f : α → α) (i j) (l : List α) : | zero => simp | succ i => simp [ih] +@[grind =] theorem drop_modify_of_lt (f : α → α) (i j) (l : List α) (h : i < j) : (l.modify i f).drop j = l.drop j := by apply ext_getElem @@ -266,6 +268,7 @@ theorem drop_modify_of_lt (f : α → α) (i j) (l : List α) (h : i < j) : intro h' omega +@[grind =] theorem drop_modify_of_ge (f : α → α) (i j) (l : List α) (h : i ≥ j) : (l.modify i f).drop j = (l.drop j).modify (i - j) f := by apply ext_getElem