Skip to content

Commit

Permalink
chore: relax List.insert to only rely BEq (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-em authored Dec 14, 2023
1 parent 88d5e17 commit 3bb8c37
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Std/Data/List/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ def indexOf [BEq α] (a : α) : List α → Nat := findIdx (· == a)
exact (go #[] _).symm

/-- Inserts an element into a list without duplication. -/
@[inline] protected def insert [DecidableEq α] (a : α) (l : List α) : List α :=
if a ∈ l then l else a :: l
@[inline] protected def insert [BEq α] (a : α) (l : List α) : List α :=
if l.elem a then l else a :: l

/--
Constructs the union of two lists, by inserting the elements of `l₁` in reverse order to `l₂`.
Expand Down
4 changes: 2 additions & 2 deletions Std/Data/List/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1069,10 +1069,10 @@ section insert
variable [DecidableEq α]

@[simp] theorem insert_of_mem {l : List α} (h : a ∈ l) : l.insert a = l := by
simp only [List.insert, if_pos h]
simp only [List.insert, elem_iff, if_pos h]

@[simp] theorem insert_of_not_mem {l : List α} (h : a ∉ l) : l.insert a = a :: l := by
simp only [List.insert, if_neg h]
simp only [List.insert, elem_iff, if_neg h]

@[simp] theorem mem_insert_iff {l : List α} : a ∈ l.insert b ↔ a = b ∨ a ∈ l := by
if h : b ∈ l then
Expand Down

0 comments on commit 3bb8c37

Please sign in to comment.