Bind operation for multisets #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
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 #
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.
join {{1, 2}, {1, 2}, {0, 1}} = {0, 1, 1, 1, 2, 2}
Equations
@[simp]
theorem
multiset.rel_join
{α : Type u_1}
{β : Type u_2}
{r : α → β → Prop}
{s : multiset (multiset α)}
{t : multiset (multiset β)}
(h : multiset.rel (multiset.rel r) s t) :
multiset.rel r s.join t.join
Bind #
@[simp]
theorem
multiset.bind_singleton
{α : Type u_1}
{β : Type u_2}
(s : multiset α)
(f : α → β) :
s.bind (λ (x : α), {f x}) = multiset.map f s
@[simp]
theorem
multiset.card_bind
{α : Type u_1}
{β : Type u_2}
(s : multiset α)
(f : α → multiset β) :
⇑multiset.card (s.bind f) = (multiset.map (⇑multiset.card ∘ f) s).sum
theorem
multiset.map_bind
{α : Type u_1}
{β : Type u_2}
{γ : Type u_3}
(m : multiset α)
(n : α → multiset β)
(f : β → γ) :
multiset.map f (m.bind n) = m.bind (λ (a : α), multiset.map f (n a))
theorem
multiset.bind_map_comm
{α : Type u_1}
{β : Type u_2}
{γ : Type u_3}
(m : multiset α)
(n : multiset β)
{f : α → β → γ} :
m.bind (λ (a : α), multiset.map (λ (b : β), f a b) n) = n.bind (λ (b : β), multiset.map (λ (a : α), f a b) m)
@[simp]
theorem
multiset.prod_bind
{α : Type u_1}
{β : Type u_2}
[comm_monoid β]
(s : multiset α)
(t : α → multiset β) :
@[simp]
theorem
multiset.sum_bind
{α : Type u_1}
{β : Type u_2}
[add_comm_monoid β]
(s : multiset α)
(t : α → multiset β) :
theorem
multiset.count_sum
{α : Type u_1}
{β : Type u_2}
[decidable_eq α]
{m : multiset β}
{f : β → multiset α}
{a : α} :
multiset.count a (multiset.map f m).sum = (multiset.map (λ (b : β), multiset.count a (f b)) m).sum
theorem
multiset.count_bind
{α : Type u_1}
{β : Type u_2}
[decidable_eq α]
{m : multiset β}
{f : β → multiset α}
{a : α} :
multiset.count a (m.bind f) = (multiset.map (λ (b : β), multiset.count a (f b)) m).sum
Product of two multisets #
@[simp]
theorem
multiset.card_product
{α : Type u_1}
{β : Type u_2}
(s : multiset α)
(t : multiset β) :
⇑multiset.card (s ×ˢ t) = ⇑multiset.card s * ⇑multiset.card t
Disjoint sum of multisets #
@[protected]
def
multiset.sigma
{α : Type u_1}
{σ : α → Type u_5}
(s : multiset α)
(t : Π (a : α), multiset (σ a)) :
sigma s t
is the dependent version of product
. It is the sum of
(a, b)
as a
ranges over s
and b
ranges over t a
.
Equations
- s.sigma t = s.bind (λ (a : α), multiset.map (sigma.mk a) (t a))
@[simp]
theorem
multiset.card_sigma
{α : Type u_1}
{σ : α → Type u_5}
(s : multiset α)
(t : Π (a : α), multiset (σ a)) :
⇑multiset.card (s.sigma t) = (multiset.map (λ (a : α), ⇑multiset.card (t a)) s).sum