The areas / V03. Sets, finite structures and big operators
Mathlib.Data.Multiset.Bind
75 declarations. Mathlib docs · Source
Bind operation for multisets
This file defines a few basic operations on Multiset, notably the monadic bind.
Main declarations
Multiset.join: The join, aka union or sum, of multisets.Multiset.bind: The bind of a multiset-indexed family of multisets.Multiset.product: Cartesian product of two multisets.Multiset.sigma: Disjoint sum of multisets in a sigma type.
Join
Bind
Product of two multisets
Disjoint sum of multisets
def Multiset.join E3 #
{α : Type u_1} → Multiset (Multiset α) → Multiset α
join S, where S is a multiset of multisets, is the lift of the list join
operation, that is, the union of all the sets.
For example, join {{1, 2}, {1, 2}, {0, 1}} = {0, 1, 1, 1, 2, 2}.
theorem Multiset.coe_join E0 #
∀ {α : Type u_1} (L : List (List α)), (↑(List.map Multiset.ofList L)).join = ↑L.flatten
theorem Multiset.join_zero E0 #
∀ {α : Type u_1}, Multiset.join 0 = 0
theorem Multiset.join_cons E0 #
∀ {α : Type u_1} (s : Multiset α) (S : Multiset (Multiset α)), (s ::ₘ S).join = s + S.join
theorem Multiset.join_add E0 #
∀ {α : Type u_1} (S T : Multiset (Multiset α)), (S + T).join = S.join + T.join
theorem Multiset.singleton_join E0 #
∀ {α : Type u_1} (a : Multiset α), {a}.join = a
theorem Multiset.mem_join E0 #
∀ {α : Type u_1} {a : α} {S : Multiset (Multiset α)}, a ∈ S.join ↔ ∃ s ∈ S, a ∈ s
theorem Multiset.card_join E0 #
∀ {α : Type u_1} (S : Multiset (Multiset α)), S.join.card = (Multiset.map Multiset.card S).sum
theorem Multiset.map_join E0 #
∀ {α : Type u_1} {β : Type v} (f : α → β) (S : Multiset (Multiset α)),
Multiset.map f S.join = (Multiset.map (Multiset.map f) S).join
theorem Multiset.prod_join E0 #
∀ {α : Type u_1} [inst : CommMonoid α] {S : Multiset (Multiset α)}, S.join.prod = (Multiset.map Multiset.prod S).prod
theorem Multiset.sum_join E0 #
∀ {α : Type u_1} [inst : AddCommMonoid α] {S : Multiset (Multiset α)}, S.join.sum = (Multiset.map Multiset.sum S).sum
theorem Multiset.rel_join E1 #
∀ {α : Type u_1} {β : Type v} {r : α → β → Prop} {s : Multiset (Multiset α)} {t : Multiset (Multiset β)},
Multiset.Rel (Multiset.Rel r) s t → Multiset.Rel r s.join t.join
theorem Multiset.filter_join E1 #
∀ {α : Type u_1} (S : Multiset (Multiset α)) (p : α → Prop) [inst : DecidablePred p],
Multiset.filter p S.join = (Multiset.map (Multiset.filter p) S).join
theorem Multiset.filterMap_join E1 #
∀ {α : Type u_1} {β : Type v} (S : Multiset (Multiset α)) (f : α → Option β),
Multiset.filterMap f S.join = (Multiset.map (Multiset.filterMap f) S).join
def Multiset.bind E3 #
{α : Type u_1} → {β : Type v} → Multiset α → (α → Multiset β) → Multiset β
s.bind f is the monad bind operation, defined as (s.map f).join. It is the union of f a as
a ranges over s.
theorem Multiset.coe_bind E0 #
∀ {α : Type u_1} {β : Type v} (l : List α) (f : α → List β), ((↑l).bind fun a ↦ ↑(f a)) = ↑(List.flatMap f l)
theorem Multiset.zero_bind E0 #
∀ {α : Type u_1} {β : Type v} (f : α → Multiset β), Multiset.bind 0 f = 0
theorem Multiset.cons_bind E0 #
∀ {α : Type u_1} {β : Type v} (a : α) (s : Multiset α) (f : α → Multiset β), (a ::ₘ s).bind f = f a + s.bind f
theorem Multiset.singleton_bind E0 #
∀ {α : Type u_1} {β : Type v} (a : α) (f : α → Multiset β), {a}.bind f = f a
theorem Multiset.add_bind E0 #
∀ {α : Type u_1} {β : Type v} (s t : Multiset α) (f : α → Multiset β), (s + t).bind f = s.bind f + t.bind f
theorem Multiset.bind_zero E0 #
∀ {α : Type u_1} {β : Type v} (s : Multiset α), (s.bind fun x ↦ 0) = 0
theorem Multiset.bind_add E0 #
∀ {α : Type u_1} {β : Type v} (s : Multiset α) (f g : α → Multiset β), (s.bind fun a ↦ f a + g a) = s.bind f + s.bind g
theorem Multiset.bind_cons E0 #
∀ {α : Type u_1} {β : Type v} (s : Multiset α) (f : α → β) (g : α → Multiset β),
(s.bind fun a ↦ f a ::ₘ g a) = Multiset.map f s + s.bind g
theorem Multiset.bind_singleton E0 #
∀ {α : Type u_1} {β : Type v} (s : Multiset α) (f : α → β), (s.bind fun x ↦ {f x}) = Multiset.map f s
theorem Multiset.mem_bind E0 #
∀ {α : Type u_1} {β : Type v} {b : β} {s : Multiset α} {f : α → Multiset β}, b ∈ s.bind f ↔ ∃ a ∈ s, b ∈ f a
theorem Multiset.card_bind E0 #
∀ {α : Type u_1} {β : Type v} (s : Multiset α) (f : α → Multiset β),
(s.bind f).card = (Multiset.map (Multiset.card ∘ f) s).sum
theorem Multiset.bind_congr E1 #
∀ {α : Type u_1} {β : Type v} {f g : α → Multiset β} {m : Multiset α}, (∀ a ∈ m, f a = g a) → m.bind f = m.bind g
theorem Multiset.bind_congr' E1 #
∀ {α : Type u_1} {β : Type v} {f g : α → Multiset β} {m m' : Multiset α},
m = m' → (∀ a ∈ m, f a = g a) → m.bind f = m'.bind g
theorem Multiset.bind_hcongr E1 #
∀ {α : Type u_1} {β β' : Type v} {m : Multiset α} {f : α → Multiset β} {f' : α → Multiset β'},
β = β' → (∀ a ∈ m, f a ≍ f' a) → m.bind f ≍ m.bind f'
theorem Multiset.map_bind E0 #
∀ {α : Type u_1} {β : Type v} {γ : Type u_2} (m : Multiset α) (n : α → Multiset β) (f : β → γ),
Multiset.map f (m.bind n) = m.bind fun a ↦ Multiset.map f (n a)
theorem Multiset.bind_map E1 #
∀ {α : Type u_1} {β : Type v} {γ : Type u_2} (m : Multiset α) (n : β → Multiset γ) (f : α → β),
(Multiset.map f m).bind n = m.bind fun a ↦ n (f a)
theorem Multiset.bind_assoc E1 #
∀ {α : Type u_1} {β : Type v} {γ : Type u_2} {s : Multiset α} {f : α → Multiset β} {g : β → Multiset γ},
(s.bind f).bind g = s.bind fun a ↦ (f a).bind g
theorem Multiset.bind_bind E1 #
∀ {α : Type u_1} {β : Type v} {γ : Type u_2} (m : Multiset α) (n : Multiset β) {f : α → β → Multiset γ},
(m.bind fun a ↦ n.bind fun b ↦ f a b) = n.bind fun b ↦ m.bind fun a ↦ f a b
theorem Multiset.bind_map_comm E1 #
∀ {α : Type u_1} {β : Type v} {γ : Type u_2} (m : Multiset α) (n : Multiset β) {f : α → β → γ},
(m.bind fun a ↦ Multiset.map (fun b ↦ f a b) n) = n.bind fun b ↦ Multiset.map (fun a ↦ f a b) m
theorem Multiset.filter_eq_bind E1 #
∀ {α : Type u_1} (m : Multiset α) (p : α → Prop) [inst : DecidablePred p],
Multiset.filter p m = m.bind fun a ↦ if p a then {a} else 0
theorem Multiset.bind_filter E1 #
∀ {α : Type u_1} {β : Type v} (m : Multiset α) (p : α → Prop) (f : α → Multiset β) [inst : DecidablePred p],
(Multiset.filter p m).bind f = m.bind fun a ↦ if p a then f a else 0
theorem Multiset.filter_bind E1 #
∀ {α : Type u_1} {β : Type v} (m : Multiset α) (f : α → Multiset β) (p : β → Prop) [inst : DecidablePred p],
Multiset.filter p (m.bind f) = m.bind fun a ↦ Multiset.filter p (f a)
theorem Multiset.filterMap_eq_bind E1 #
∀ {α : Type u_1} {β : Type v} (m : Multiset α) (f : α → Option β),
Multiset.filterMap f m = m.bind fun a ↦ (Option.map singleton (f a)).getD 0
theorem Multiset.bind_filterMap E1 #
∀ {α : Type u_1} {β : Type v} {γ : Type u_2} (m : Multiset α) (f : α → Option β) (g : β → Multiset γ),
(Multiset.filterMap f m).bind g = m.bind fun a ↦ (Option.map g (f a)).getD 0
theorem Multiset.filterMap_bind E1 #
∀ {α : Type u_1} {β : Type v} {γ : Type u_2} (m : Multiset α) (f : α → Multiset β) (g : β → Option γ),
Multiset.filterMap g (m.bind f) = m.bind fun a ↦ Multiset.filterMap g (f a)
theorem Multiset.prod_bind E0 #
∀ {α : Type u_1} {β : Type v} [inst : CommMonoid β] (s : Multiset α) (t : α → Multiset β),
(s.bind t).prod = (Multiset.map (fun a ↦ (t a).prod) s).prod
theorem Multiset.sum_bind E0 #
∀ {α : Type u_1} {β : Type v} [inst : AddCommMonoid β] (s : Multiset α) (t : α → Multiset β),
(s.bind t).sum = (Multiset.map (fun a ↦ (t a).sum) s).sum
theorem Multiset.rel_bind E1 #
∀ {α : Type u_1} {β : Type v} {γ : Type u_2} {δ : Type u_3} {r : α → β → Prop} {p : γ → δ → Prop} {s : Multiset α}
{t : Multiset β} {f : α → Multiset γ} {g : β → Multiset δ},
Relator.LiftFun r (Multiset.Rel p) f g → Multiset.Rel r s t → Multiset.Rel p (s.bind f) (t.bind g)
theorem Multiset.count_sum E1 #
∀ {α : Type u_1} {β : Type v} [inst : DecidableEq α] {m : Multiset β} {f : β → Multiset α} {a : α},
Multiset.count a (Multiset.map f m).sum = (Multiset.map (fun b ↦ Multiset.count a (f b)) m).sum
theorem Multiset.count_bind E1 #
∀ {α : Type u_1} {β : Type v} [inst : DecidableEq α] {m : Multiset β} {f : β → Multiset α} {a : α},
Multiset.count a (m.bind f) = (Multiset.map (fun b ↦ Multiset.count a (f b)) m).sum
theorem Multiset.le_bind E1 #
∀ {α : Type u_4} {β : Type u_5} {f : α → Multiset β} (S : Multiset α) {x : α}, x ∈ S → f x ≤ S.bind f
theorem Multiset.attach_bind_coe E0 #
∀ {α : Type u_1} {β : Type v} (s : Multiset α) (f : α → Multiset β), (s.attach.bind fun i ↦ f ↑i) = s.bind f
theorem Multiset.nodup_bind E0 #
∀ {α : Type u_1} {β : Type v} {s : Multiset α} {f : α → Multiset β},
(s.bind f).Nodup ↔ (∀ a ∈ s, (f a).Nodup) ∧ Multiset.Pairwise (Function.onFun Disjoint f) s
theorem Multiset.dedup_bind_dedup E0 #
∀ {α : Type u_1} {β : Type v} [inst : DecidableEq α] [inst_1 : DecidableEq β] (s : Multiset α) (f : α → Multiset β),
(s.dedup.bind f).dedup = (s.bind f).dedup
theorem Multiset.fold_bind E1 #
∀ {α : Type u_1} (op : α → α → α) [hc : Std.Commutative op] [ha : Std.Associative op] {ι : Type u_4} (s : Multiset ι)
(t : ι → Multiset α) (b : ι → α) (b₀ : α),
Multiset.fold op (Multiset.fold op b₀ (Multiset.map b s)) (s.bind t) =
Multiset.fold op b₀ (Multiset.map (fun i ↦ Multiset.fold op (b i) (t i)) s)
def Multiset.product E3 #
{α : Type u_1} → {β : Type v} → Multiset α → Multiset β → Multiset (α × β)
The multiplicity of (a, b) in s ×ˢ t is
the product of the multiplicity of a in s and b in t.
instance Multiset.instSProd E0 #
{α : Type u_1} → {β : Type v} → SProd (Multiset α) (Multiset β) (Multiset (α × β))
theorem Multiset.coe_product E0 #
∀ {α : Type u_1} {β : Type v} (l₁ : List α) (l₂ : List β), ↑l₁ ×ˢ ↑l₂ = ↑(l₁ ×ˢ l₂)
theorem Multiset.zero_product E0 #
∀ {α : Type u_1} {β : Type v} (t : Multiset β), 0 ×ˢ t = 0
theorem Multiset.cons_product E0 #
∀ {α : Type u_1} {β : Type v} (a : α) (s : Multiset α) (t : Multiset β),
(a ::ₘ s) ×ˢ t = Multiset.map (Prod.mk a) t + s ×ˢ t
theorem Multiset.product_zero E0 #
∀ {α : Type u_1} {β : Type v} (s : Multiset α), s ×ˢ 0 = 0
theorem Multiset.product_cons E0 #
∀ {α : Type u_1} {β : Type v} (b : β) (s : Multiset α) (t : Multiset β),
s ×ˢ (b ::ₘ t) = Multiset.map (fun a ↦ (a, b)) s + s ×ˢ t
theorem Multiset.product_singleton E0 #
∀ {α : Type u_1} {β : Type v} (a : α) (b : β), {a} ×ˢ {b} = {(a, b)}
theorem Multiset.add_product E0 #
∀ {α : Type u_1} {β : Type v} (s t : Multiset α) (u : Multiset β), (s + t) ×ˢ u = s ×ˢ u + t ×ˢ u
theorem Multiset.product_add E0 #
∀ {α : Type u_1} {β : Type v} (s : Multiset α) (t u : Multiset β), s ×ˢ (t + u) = s ×ˢ t + s ×ˢ u
theorem Multiset.card_product E0 #
∀ {α : Type u_1} {β : Type v} (s : Multiset α) (t : Multiset β), (s ×ˢ t).card = s.card * t.card
theorem Multiset.mem_product E0 #
∀ {α : Type u_1} {β : Type v} {s : Multiset α} {t : Multiset β} {p : α × β}, p ∈ s ×ˢ t ↔ p.1 ∈ s ∧ p.2 ∈ t
theorem Multiset.Nodup.product E1 #
∀ {α : Type u_1} {β : Type v} {s : Multiset α} {t : Multiset β}, s.Nodup → t.Nodup → (s ×ˢ t).Nodup
theorem Multiset.map_swap_product E0 #
∀ {α : Type u_1} {β : Type v} (s : Multiset α) (t : Multiset β), Multiset.map Prod.swap (s ×ˢ t) = t ×ˢ s
theorem Multiset.prod_map_product_eq_prod_prod E1 #
∀ {α : Type u_1} {β : Type v} {M : Type u_4} [inst : CommMonoid M] (s : Multiset α) (t : Multiset β) (f : α × β → M),
(Multiset.map f (s ×ˢ t)).prod = (Multiset.map (fun i ↦ (Multiset.map (fun j ↦ f (i, j)) t).prod) s).prod
def Multiset.sigma E3 #
{α : Type u_1} → {σ : α → Type u_4} → Multiset α → ((a : α) → Multiset (σ a)) → Multiset ((a : α) × σ a)
Multiset.sigma s t is the dependent version of Multiset.product. It is the sum of
(a, b) as a ranges over s and b ranges over t a.
theorem Multiset.coe_sigma E0 #
∀ {α : Type u_1} {σ : α → Type u_4} (l₁ : List α) (l₂ : (a : α) → List (σ a)),
((↑l₁).sigma fun a ↦ ↑(l₂ a)) = ↑(l₁.sigma l₂)
theorem Multiset.zero_sigma E0 #
∀ {α : Type u_1} {σ : α → Type u_4} (t : (a : α) → Multiset (σ a)), Multiset.sigma 0 t = 0
theorem Multiset.cons_sigma E0 #
∀ {α : Type u_1} {σ : α → Type u_4} (a : α) (s : Multiset α) (t : (a : α) → Multiset (σ a)),
(a ::ₘ s).sigma t = Multiset.map (Sigma.mk a) (t a) + s.sigma t
theorem Multiset.sigma_singleton E0 #
∀ {α : Type u_1} {β : Type v} (a : α) (b : α → β), ({a}.sigma fun a ↦ {b a}) = {⟨a, b a⟩}
theorem Multiset.add_sigma E0 #
∀ {α : Type u_1} {σ : α → Type u_4} (s t : Multiset α) (u : (a : α) → Multiset (σ a)),
(s + t).sigma u = s.sigma u + t.sigma u
theorem Multiset.sigma_add E0 #
∀ {α : Type u_1} {σ : α → Type u_4} (s : Multiset α) (t u : (a : α) → Multiset (σ a)),
(s.sigma fun a ↦ t a + u a) = s.sigma t + s.sigma u
theorem Multiset.card_sigma E0 #
∀ {α : Type u_1} {σ : α → Type u_4} (s : Multiset α) (t : (a : α) → Multiset (σ a)),
(s.sigma t).card = (Multiset.map (fun a ↦ (t a).card) s).sum
theorem Multiset.mem_sigma E0 #
∀ {α : Type u_1} {σ : α → Type u_4} {s : Multiset α} {t : (a : α) → Multiset (σ a)} {p : (a : α) × σ a},
p ∈ s.sigma t ↔ p.fst ∈ s ∧ p.snd ∈ t p.fst
theorem Multiset.Nodup.sigma E1 #
∀ {α : Type u_1} {s : Multiset α} {σ : α → Type u_5} {t : (a : α) → Multiset (σ a)},
s.Nodup → (∀ (a : α), (t a).Nodup) → (s.sigma t).Nodup