Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use List.getElem rather than List.get #19241

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Mathlib/Analysis/Calculus/FDeriv/Mul.lean
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ theorem HasFDerivWithinAt.list_prod' {l : List ι} {x : E}
smulRight (f' l[i]) ((l.drop (.succ i)).map (f · x)).prod) s x := by
simp only [← List.finRange_map_get l, List.map_map]
refine .congr_fderiv (hasFDerivAt_list_prod_finRange'.comp_hasFDerivWithinAt x
(hasFDerivWithinAt_pi.mpr fun i ↦ h l[i] (l.get_mem i i.isLt))) ?_
(hasFDerivWithinAt_pi.mpr fun i ↦ h l[i] (l.getElem_mem i.isLt))) ?_
kim-em marked this conversation as resolved.
Show resolved Hide resolved
ext m
simp [← List.map_map]

Expand Down
4 changes: 2 additions & 2 deletions Mathlib/Combinatorics/Enumerative/Composition.lean
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,15 @@ theorem sum_blocksFun : ∑ i, c.blocksFun i = n := by
conv_rhs => rw [← c.blocks_sum, ← ofFn_blocksFun, sum_ofFn]

theorem blocksFun_mem_blocks (i : Fin c.length) : c.blocksFun i ∈ c.blocks :=
get_mem _ _ _
getElem_mem _
kim-em marked this conversation as resolved.
Show resolved Hide resolved

@[simp]
theorem one_le_blocks {i : ℕ} (h : i ∈ c.blocks) : 1 ≤ i :=
c.blocks_pos h

@[simp]
theorem one_le_blocks' {i : ℕ} (h : i < c.length) : 1 ≤ c.blocks[i] :=
c.one_le_blocks (get_mem (blocks c) i h)
c.one_le_blocks (getElem_mem h)

@[simp]
theorem blocks_pos' (i : ℕ) (h : i < c.length) : 0 < c.blocks[i] :=
Expand Down
4 changes: 2 additions & 2 deletions Mathlib/Data/Finset/Sort.lean
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ theorem sorted_zero_eq_min'_aux (s : Finset α) (h : 0 < (s.sort (· ≤ ·)).le
obtain ⟨i, hi⟩ : ∃ i, l.get i = s.min' H := List.mem_iff_get.1 this
rw [← hi]
exact (s.sort_sorted (· ≤ ·)).rel_get_of_le (Nat.zero_le i)
· have : l.get ⟨0, h⟩ ∈ s := (Finset.mem_sort (α := α) (· ≤ ·)).1 (List.get_mem l 0 h)
· have : l.get ⟨0, h⟩ ∈ s := (Finset.mem_sort (α := α) (· ≤ ·)).1 (List.getElem_mem h)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one also seems wrong, since the statement is about .get

exact s.min'_le _ this

theorem sorted_zero_eq_min' {s : Finset α} {h : 0 < (s.sort (· ≤ ·)).length} :
Expand All @@ -130,7 +130,7 @@ theorem sorted_last_eq_max'_aux (s : Finset α)
let l := s.sort (· ≤ ·)
apply le_antisymm
· have : l.get ⟨(s.sort (· ≤ ·)).length - 1, h⟩ ∈ s :=
(Finset.mem_sort (α := α) (· ≤ ·)).1 (List.get_mem l _ h)
(Finset.mem_sort (α := α) (· ≤ ·)).1 (List.getElem_mem h)
exact s.le_max' _ this
· have : s.max' H ∈ l := (Finset.mem_sort (α := α) (· ≤ ·)).mpr (s.max'_mem H)
obtain ⟨i, hi⟩ : ∃ i, l.get i = s.max' H := List.mem_iff_get.1 this
Expand Down
10 changes: 5 additions & 5 deletions Mathlib/Data/List/Cycle.lean
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ theorem prev_ne_cons_cons (y z : α) (h : x ∈ y :: z :: l) (hy : x ≠ y) (hz
· rw [prev, dif_neg hy, if_neg hz]

theorem next_mem (h : x ∈ l) : l.next x h ∈ l :=
nextOr_mem (get_mem _ _ _)
nextOr_mem (getElem_mem _)

theorem prev_mem (h : x ∈ l) : l.prev x h ∈ l := by
cases' l with hd tl
Expand All @@ -233,7 +233,7 @@ theorem prev_mem (h : x ∈ l) : l.prev x h ∈ l := by
· exact mem_cons_of_mem _ (hl _ _)

theorem next_get (l : List α) (h : Nodup l) (i : Fin l.length) :
next l (l.get i) (get_mem _ _ _) =
next l (l.get i) (getElem_mem _) =
l.get ⟨(i + 1) % l.length, Nat.mod_lt _ (i.1.zero_le.trans_lt i.2)⟩ :=
match l, h, i with
| [], _, i => by simpa using i.2
Expand All @@ -254,7 +254,7 @@ theorem next_get (l : List α) (h : Nodup l) (i : Fin l.length) :
· subst hi'
rw [next_getLast_cons]
· simp [hi', get]
· rw [get_cons_succ]; exact get_mem _ _ _
· rw [get_cons_succ]; exact getElem_mem _
· exact hx'
· simp [getLast_eq_getElem]
· exact hn.of_cons
Expand All @@ -271,12 +271,12 @@ theorem next_get (l : List α) (h : Nodup l) (i : Fin l.length) :
intro h
have := nodup_iff_injective_get.1 hn h
simp at this; simp [this] at hi'
· rw [get_cons_succ]; exact get_mem _ _ _
· rw [get_cons_succ]; exact getElem_mem _

-- Unused variable linter incorrectly reports that `h` is unused here.
set_option linter.unusedVariables false in
theorem prev_get (l : List α) (h : Nodup l) (i : Fin l.length) :
prev l (l.get i) (get_mem _ _ _) =
prev l (l.get i) (getElem_mem _) =
l.get ⟨(i + (l.length - 1)) % l.length, Nat.mod_lt _ i.pos⟩ :=
match l with
| [] => by simpa using i.2
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/Data/List/NodupEquivFin.lean
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ variable [DecidableEq α]
the set of elements of `l`. -/
@[simps]
def getEquiv (l : List α) (H : Nodup l) : Fin (length l) ≃ { x // x ∈ l } where
toFun i := ⟨get l i, get_mem l i i.2⟩
toFun i := ⟨get l i, getElem_mem i.2⟩
invFun x := ⟨indexOf (↑x) l, indexOf_lt_length.2 x.2⟩
left_inv i := by simp only [List.get_indexOf, eq_self_iff_true, Fin.eta, Subtype.coe_mk, H]
right_inv x := by simp
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/Data/Vector/Mem.lean
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ variable {α β : Type*} {n : ℕ} (a a' : α)
@[simp]
theorem get_mem (i : Fin n) (v : Vector α n) : v.get i ∈ v.toList := by
rw [get_eq_get]
exact List.get_mem _ _ _
exact List.getElem_mem _

theorem mem_iff_get (v : Vector α n) : a ∈ v.toList ↔ ∃ i, v.get i = a := by
simp only [List.mem_iff_get, Fin.exists_iff, Vector.get_eq_get]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ theorem exists_approx_aux (n : ℕ) (h : abv.IsAdmissible) :
/-- This proof was nicer prior to https://github.com/leanprover/lean4/pull/4400.
Please feel welcome to improve it, by avoiding use of `List.get` in favour of `GetElem`. -/
have : ∀ i h, t ((Finset.univ.filter fun x ↦ t x = s).toList.get ⟨i, h⟩) = s := fun i h ↦
(Finset.mem_filter.mp (Finset.mem_toList.mp (List.get_mem _ i h))).2
(Finset.mem_filter.mp (Finset.mem_toList.mp (List.getElem_mem h))).2
simp only [Nat.succ_eq_add_one, Finset.length_toList, List.get_eq_getElem] at this
simp only [Nat.succ_eq_add_one, List.get_eq_getElem, Fin.coe_castLE]
rw [this _ (Nat.lt_of_le_of_lt (Nat.le_of_lt_succ i₁.2) hs),
Expand Down
Loading