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 #
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 #
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
.
Equations
- s.bind f = (multiset.map f s).join
@[simp]
@[simp]
@[simp]
@[simp]
theorem
multiset.bind_cons
{α : Type u_1}
{β : Type u_2}
(s : multiset α)
(f : α → β)
(g : α → multiset β) :
@[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
{α : Type u_1}
{β : Type u_2}
{γ : Type u_3}
(m : multiset α)
(n : β → multiset γ)
(f : α → β) :
(multiset.map f m).bind n = m.bind (λ (a : α), n (f 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.rel_bind
{α : Type u_1}
{β : Type u_2}
{γ : Type u_3}
{δ : Type u_4}
{r : α → β → Prop}
{p : γ → δ → Prop}
{s : multiset α}
{t : multiset β}
{f : α → multiset γ}
{g : β → multiset δ}
(h : (r ⇒ multiset.rel p) f g)
(hst : multiset.rel r s t) :
multiset.rel p (s.bind f) (t.bind g)
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]
@[simp]
@[simp]
theorem
multiset.card_product
{α : Type u_1}
{β : Type u_2}
(s : multiset α)
(t : multiset β) :
⇑multiset.card (s.product 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)) :
multiset (Σ (a : α), σ 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]
@[simp]
@[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