mathlib3 documentation

data.list.dedup

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]
theorem list.dedup_cons_of_mem' {α : Type u} [decidable_eq α] {a : α} {l : list α} (h : a l.dedup) :
(a :: l).dedup = l.dedup
theorem list.dedup_cons_of_not_mem' {α : Type u} [decidable_eq α] {a : α} {l : list α} (h : a l.dedup) :
(a :: l).dedup = a :: l.dedup
@[simp]
theorem list.mem_dedup {α : Type u} [decidable_eq α] {a : α} {l : list α} :
a l.dedup a l
@[simp]
theorem list.dedup_cons_of_mem {α : Type u} [decidable_eq α] {a : α} {l : list α} (h : a l) :
(a :: l).dedup = l.dedup
@[simp]
theorem list.dedup_cons_of_not_mem {α : Type u} [decidable_eq α] {a : α} {l : list α} (h : a l) :
(a :: l).dedup = a :: l.dedup
theorem list.dedup_sublist {α : Type u} [decidable_eq α] (l : list α) :
l.dedup <+ l
theorem list.dedup_subset {α : Type u} [decidable_eq α] (l : list α) :
theorem list.subset_dedup {α : Type u} [decidable_eq α] (l : list α) :
theorem list.nodup_dedup {α : Type u} [decidable_eq α] (l : list α) :
theorem list.head_dedup {α : Type u} [decidable_eq α] [inhabited α] (l : list α) :
theorem list.tail_dedup {α : Type u} [decidable_eq α] [inhabited α] (l : list α) :
theorem list.dedup_eq_self {α : Type u} [decidable_eq α] {l : list α} :
theorem list.dedup_eq_cons {α : Type u} [decidable_eq α] (l : list α) (a : α) (l' : list α) :
l.dedup = a :: l' a l a l' l.dedup.tail = l'
@[simp]
theorem list.dedup_eq_nil {α : Type u} [decidable_eq α] (l : list α) :
@[protected]
theorem list.nodup.dedup {α : Type u} [decidable_eq α] {l : list α} (h : l.nodup) :
l.dedup = l
@[simp]
theorem list.dedup_idempotent {α : Type u} [decidable_eq α] {l : list α} :
theorem list.dedup_append {α : Type u} [decidable_eq α] (l₁ l₂ : list α) :
(l₁ ++ l₂).dedup = l₁ l₂.dedup
theorem list.replicate_dedup {α : Type u} [decidable_eq α] {x : α} {k : } :
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

theorem list.sum_map_count_dedup_eq_length {α : Type u} [decidable_eq α] (l : list α) :
(list.map (λ (x : α), list.count x l) l.dedup).sum = l.length