Erasure of duplicates in a list #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
This file proves basic results about list.dedup
(definition in data.list.defs
).
dedup l
returns l
without its duplicates. It keeps the earliest (that is, rightmost)
occurrence of each.
Tags #
duplicate, multiplicity, nodup, nub
@[simp]
@[simp]
@[protected]
@[simp]
theorem
list.count_dedup
{α : Type u}
[decidable_eq α]
(l : list α)
(a : α) :
list.count a l.dedup = ite (a ∈ l) 1 0
theorem
list.sum_map_count_dedup_filter_eq_countp
{α : Type u}
[decidable_eq α]
(p : α → Prop)
[decidable_pred p]
(l : list α) :
(list.map (λ (x : α), list.count x l) (list.filter p l.dedup)).sum = list.countp p l
Summing the count of x
over a list filtered by some p
is just countp
applied to p