Lists with no duplicates #
List.Nodup
is defined in Data/List/Basic
. In this file we prove various properties of this
predicate.
theorem
List.Nodup.cons
{α : Type u}
{l : List α}
{a : α}
(ha : a ∉ l)
(hl : l.Nodup)
:
(a :: l).Nodup
theorem
List.nodup_iff_injective_getElem
{α : Type u}
{l : List α}
:
l.Nodup ↔ Function.Injective fun (i : Fin l.length) => l[↑i]
theorem
List.indexOf_getElem
{α : Type u}
[DecidableEq α]
{l : List α}
(H : l.Nodup)
(i : ℕ)
(h : i < l.length)
:
theorem
List.get_indexOf
{α : Type u}
[DecidableEq α]
{l : List α}
(H : l.Nodup)
(i : Fin l.length)
:
@[simp]
theorem
List.count_eq_one_of_mem
{α : Type u}
[DecidableEq α]
{a : α}
{l : List α}
(d : l.Nodup)
(h : a ∈ l)
:
theorem
List.disjoint_of_nodup_append
{α : Type u}
{l₁ l₂ : List α}
(d : (l₁ ++ l₂).Nodup)
:
l₁.Disjoint l₂
theorem
List.Nodup.append
{α : Type u}
{l₁ l₂ : List α}
(d₁ : l₁.Nodup)
(d₂ : l₂.Nodup)
(dj : l₁.Disjoint l₂)
:
(l₁ ++ l₂).Nodup
theorem
List.Nodup.map
{α : Type u}
{β : Type v}
{l : List α}
{f : α → β}
(hf : Function.Injective f)
:
l.Nodup → (map f l).Nodup
theorem
List.nodup_map_iff
{α : Type u}
{β : Type v}
{f : α → β}
{l : List α}
(hf : Function.Injective f)
:
Alias of the reverse direction of List.nodup_attach
.
Alias of the forward direction of List.nodup_attach
.
theorem
List.Nodup.filter
{α : Type u}
(p : α → Bool)
{l : List α}
:
l.Nodup → (List.filter p l).Nodup
theorem
List.Nodup.erase_getElem
{α : Type u}
[DecidableEq α]
{l : List α}
(hl : l.Nodup)
(i : ℕ)
(h : i < l.length)
:
l.erase l[i] = l.eraseIdx i
theorem
List.Nodup.erase_get
{α : Type u}
[DecidableEq α]
{l : List α}
(hl : l.Nodup)
(i : Fin l.length)
:
l.erase (l.get i) = l.eraseIdx ↑i
theorem
List.Nodup.diff
{α : Type u}
{l₁ l₂ : List α}
[DecidableEq α]
:
l₁.Nodup → (l₁.diff l₂).Nodup
@[deprecated List.nodup_flatten (since := "2025-10-15")]
Alias of List.nodup_flatten
.
@[deprecated List.nodup_flatMap (since := "2025-10-16")]
theorem
List.nodup_bind
{α : Type u}
{β : Type v}
{l₁ : List α}
{f : α → List β}
:
(l₁.flatMap f).Nodup ↔ (∀ x ∈ l₁, (f x).Nodup) ∧ Pairwise (Function.onFun Disjoint f) l₁
Alias of List.nodup_flatMap
.
theorem
List.Nodup.concat
{α : Type u}
{l : List α}
{a : α}
(h : a ∉ l)
(h' : l.Nodup)
:
(l.concat a).Nodup
theorem
List.Nodup.insert
{α : Type u}
{l : List α}
{a : α}
[DecidableEq α]
(h : l.Nodup)
:
(List.insert a l).Nodup
theorem
List.Nodup.union
{α : Type u}
{l₂ : List α}
[DecidableEq α]
(l₁ : List α)
(h : l₂.Nodup)
:
(l₁ ∪ l₂).Nodup
theorem
List.Nodup.inter
{α : Type u}
{l₁ : List α}
[DecidableEq α]
(l₂ : List α)
:
l₁.Nodup → (l₁ ∩ l₂).Nodup
theorem
List.Nodup.diff_eq_filter
{α : Type u}
[BEq α]
[LawfulBEq α]
{l₁ l₂ : List α}
:
l₁.Nodup → l₁.diff l₂ = List.filter (fun (x : α) => decide (x ∉ l₂)) l₁
theorem
List.Nodup.mem_diff_iff
{α : Type u}
{l₁ l₂ : List α}
{a : α}
[DecidableEq α]
(hl₁ : l₁.Nodup)
:
theorem
List.Nodup.set
{α : Type u}
{l : List α}
{n : ℕ}
{a : α}
:
l.Nodup → a ∉ l → (l.set n a).Nodup
theorem
List.Nodup.map_update
{α : Type u}
{β : Type v}
[DecidableEq α]
{l : List α}
(hl : l.Nodup)
(f : α → β)
(x : α)
(y : β)
:
theorem
List.Nodup.take_eq_filter_mem
{α : Type u}
[DecidableEq α]
{l : List α}
{n : ℕ}
:
l.Nodup → take n l = List.filter (fun (a : α) => elem a (take n l)) l