chore: missing [@grind] annotations for List/Array.modify` (#8601)

This commit is contained in:
Kim Morrison 2025-06-03 14:13:01 +10:00 committed by GitHub
parent 310a123901
commit 7adea80123
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 10 deletions

View file

@ -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]

View file

@ -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