The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V03. Sets, finite structures and big operators

Mathlib.Data.Multiset.Count

47 declarations and 1 deprecated aliases. Mathlib docs · Source

Counting multiplicity in a multiset

countP

Multiplicity of an element

Lift a relation to Multisets

theorem Multiset.countP.congr_simp E1 #

∀ {α : Type u_1} (p p_1 : α → Prop),
  p = p_1 →
    ∀ {inst : DecidablePred p} [inst_1 : DecidablePred p_1] (s s_1 : Multiset α),
      s = s_1 → Multiset.countP p s = Multiset.countP p_1 s_1

theorem Multiset.count.congr_simp E1 #

∀ {α : Type u_1} {inst : DecidableEq α} [inst_1 : DecidableEq α] (a a_1 : α),
  a = a_1 → ∀ (a_2 a_3 : Multiset α), a_2 = a_3 → Multiset.count a a_2 = Multiset.count a_1 a_3

def Multiset.countP E1 #

{α : Type u_1} → (p : α → Prop) → [DecidablePred p] → Multiset α → ℕ

countP p s counts the number of elements of s (with multiplicity) that satisfy p.

theorem Multiset.coe_countP E0 #

∀ {α : Type u_1} (p : α → Prop) [inst : DecidablePred p] (l : List α),
  Multiset.countP p ↑l = List.countP (fun b ↦ decide (p b)) l

theorem Multiset.countP_zero E0 #

∀ {α : Type u_1} (p : α → Prop) [inst : DecidablePred p], Multiset.countP p 0 = 0

theorem Multiset.countP_cons_of_pos E0 #

∀ {α : Type u_1} {p : α → Prop} [inst : DecidablePred p] {a : α} (s : Multiset α),
  p a → Multiset.countP p (a ::ₘ s) = Multiset.countP p s + 1

theorem Multiset.countP_cons_of_neg E0 #

∀ {α : Type u_1} {p : α → Prop} [inst : DecidablePred p] {a : α} (s : Multiset α),
  ¬p a → Multiset.countP p (a ::ₘ s) = Multiset.countP p s

theorem Multiset.countP_cons E1 #

∀ {α : Type u_1} (p : α → Prop) [inst : DecidablePred p] (b : α) (s : Multiset α),
  Multiset.countP p (b ::ₘ s) = Multiset.countP p s + if p b then 1 else 0

theorem Multiset.countP_le_card E1 #

∀ {α : Type u_1} (p : α → Prop) [inst : DecidablePred p] (s : Multiset α), Multiset.countP p s ≤ s.card

theorem Multiset.card_eq_countP_add_countP E1 #

∀ {α : Type u_1} (p : α → Prop) [inst : DecidablePred p] (s : Multiset α),
  s.card = Multiset.countP p s + Multiset.countP (fun x ↦ ¬p x) s

theorem Multiset.countP_le_of_le E1 #

∀ {α : Type u_1} (p : α → Prop) [inst : DecidablePred p] {s t : Multiset α},
  s ≤ t → Multiset.countP p s ≤ Multiset.countP p t

theorem Multiset.countP_true E0 #

∀ {α : Type u_1} {s : Multiset α}, Multiset.countP (fun x ↦ True) s = s.card

theorem Multiset.countP_False E0 #

∀ {α : Type u_1} {s : Multiset α}, Multiset.countP (fun x ↦ False) s = 0

theorem Multiset.countP_attach E1 #

∀ {α : Type u_1} (p : α → Prop) [inst : DecidablePred p] (s : Multiset α),
  Multiset.countP (fun a ↦ p ↑a) s.attach = Multiset.countP p s

theorem Multiset.countP_pos E1 #

∀ {α : Type u_1} {p : α → Prop} [inst : DecidablePred p] {s : Multiset α}, 0 < Multiset.countP p s ↔ ∃ a ∈ s, p a

theorem Multiset.countP_eq_zero E1 #

∀ {α : Type u_1} {p : α → Prop} [inst : DecidablePred p] {s : Multiset α}, Multiset.countP p s = 0 ↔ ∀ a ∈ s, ¬p a

theorem Multiset.countP_eq_card E1 #

∀ {α : Type u_1} {p : α → Prop} [inst : DecidablePred p] {s : Multiset α}, Multiset.countP p s = s.card ↔ ∀ a ∈ s, p a

theorem Multiset.countP_pos_of_mem E1 #

∀ {α : Type u_1} {p : α → Prop} [inst : DecidablePred p] {s : Multiset α} {a : α}, a ∈ s → p a → 0 < Multiset.countP p s

theorem Multiset.countP_congr E1 #

∀ {α : Type u_1} {s s' : Multiset α},
  s = s' →
    ∀ {p p' : α → Prop} [inst : DecidablePred p] [inst_1 : DecidablePred p'],
      (∀ x ∈ s, p x = p' x) → Multiset.countP p s = Multiset.countP p' s'

def Multiset.count E1 #

{α : Type u_1} → [DecidableEq α] → α → Multiset α → ℕ

count a s is the multiplicity of a in s.

theorem Multiset.coe_count E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (a : α) (l : List α), Multiset.count a ↑l = List.count a l

theorem Multiset.count_zero E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (a : α), Multiset.count a 0 = 0

theorem Multiset.count_cons_self E0 #

∀ {α : Type u_1} [inst : DecidableEq α] (a : α) (s : Multiset α), Multiset.count a (a ::ₘ s) = Multiset.count a s + 1

theorem Multiset.count_cons_of_ne E0 #

∀ {α : Type u_1} [inst : DecidableEq α] {a b : α},
  a ≠ b → ∀ (s : Multiset α), Multiset.count a (b ::ₘ s) = Multiset.count a s

theorem Multiset.count_le_card E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (a : α) (s : Multiset α), Multiset.count a s ≤ s.card

theorem Multiset.count_le_of_le E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (a : α) {s t : Multiset α}, s ≤ t → Multiset.count a s ≤ Multiset.count a t

theorem Multiset.count_le_count_cons E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (a b : α) (s : Multiset α), Multiset.count a s ≤ Multiset.count a (b ::ₘ s)

theorem Multiset.count_cons E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (a b : α) (s : Multiset α),
  Multiset.count a (b ::ₘ s) = Multiset.count a s + if a = b then 1 else 0

theorem Multiset.count_singleton_self E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (a : α), Multiset.count a {a} = 1

theorem Multiset.count_singleton E1 #

∀ {α : Type u_1} [inst : DecidableEq α] (a b : α), Multiset.count a {b} = if a = b then 1 else 0

theorem Multiset.count_attach E0 #

∀ {α : Type u_1} [inst : DecidableEq α] {s : Multiset α} (a : { x // x ∈ s }),
  Multiset.count a s.attach = Multiset.count (↑a) s

theorem Multiset.count_pos E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {a : α} {s : Multiset α}, 0 < Multiset.count a s ↔ a ∈ s

theorem Multiset.one_le_count_iff_mem E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {a : α} {s : Multiset α}, 1 ≤ Multiset.count a s ↔ a ∈ s

theorem Multiset.count_eq_zero_of_notMem E0 #

∀ {α : Type u_1} [inst : DecidableEq α] {a : α} {s : Multiset α}, a ∉ s → Multiset.count a s = 0

theorem Multiset.count_ne_zero E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {s : Multiset α} {a : α}, Multiset.count a s ≠ 0 ↔ a ∈ s

theorem Multiset.count_eq_zero E0 #

∀ {α : Type u_1} [inst : DecidableEq α] {s : Multiset α} {a : α}, Multiset.count a s = 0 ↔ a ∉ s

theorem Multiset.count_eq_card E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {a : α} {s : Multiset α}, Multiset.count a s = s.card ↔ ∀ x ∈ s, a = x

theorem Multiset.ext E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {s t : Multiset α}, s = t ↔ ∀ (a : α), Multiset.count a s = Multiset.count a t

theorem Multiset.ext'_iff E0 #

∀ {α : Type u_1} [inst : DecidableEq α] {s t : Multiset α}, s = t ↔ ∀ (a : α), Multiset.count a s = Multiset.count a t

theorem Multiset.ext' E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {s t : Multiset α}, (∀ (a : α), Multiset.count a s = Multiset.count a t) → s = t

theorem Multiset.count_injective E1 #

∀ {α : Type u_1} [inst : DecidableEq α], Function.Injective fun s a ↦ Multiset.count a s

theorem Multiset.le_iff_count E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {s t : Multiset α}, s ≤ t ↔ ∀ (a : α), Multiset.count a s ≤ Multiset.count a t

theorem Multiset.Rel.countP_eq E0 #

∀ {α : Type u_1} (r : α → α → Prop) [IsTrans α r] [Std.Symm r] {s t : Multiset α} (x : α) [inst : DecidablePred (r x)],
  Multiset.Rel r s t → Multiset.countP (r x) s = Multiset.countP (r x) t

theorem Multiset.nodup_iff_count_le_one E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {s : Multiset α}, s.Nodup ↔ ∀ (a : α), Multiset.count a s ≤ 1

theorem Multiset.nodup_iff_count_eq_one E1 #

∀ {α : Type u_1} {s : Multiset α} [inst : DecidableEq α], s.Nodup ↔ ∀ a ∈ s, Multiset.count a s = 1

theorem Multiset.count_eq_one_of_mem E0 #

∀ {α : Type u_1} [inst : DecidableEq α] {a : α} {s : Multiset α}, s.Nodup → a ∈ s → Multiset.count a s = 1

theorem Multiset.count_eq_of_nodup E1 #

∀ {α : Type u_1} [inst : DecidableEq α] {a : α} {s : Multiset α}, s.Nodup → Multiset.count a s = if a ∈ s then 1 else 0

Deprecated aliases

NameNew nameSince
Multiset.countP_TrueMultiset.countP_true2026-10-27