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
Instances For
@[simp]
@[simp]
Bind #
@[simp]
theorem
Multiset.prod_bind
{α : Type u_1}
{β : Type v}
[CommMonoid β]
(s : Multiset α)
(t : α → Multiset β)
:
@[simp]
theorem
Multiset.sum_bind
{α : Type u_1}
{β : Type v}
[AddCommMonoid β]
(s : Multiset α)
(t : α → Multiset β)
:
@[simp]
theorem
Multiset.dedup_bind_dedup
{α : Type u_1}
{β : Type v}
[DecidableEq α]
[DecidableEq β]
(s : Multiset α)
(f : α → Multiset β)
:
(s.dedup.bind f).dedup = (s.bind f).dedup
Product of two multisets #
Equations
- Multiset.instSProd = { sprod := Multiset.product }
Disjoint sum of multisets #
def
Multiset.sigma
{α : Type u_1}
{σ : α → Type u_4}
(s : Multiset α)
(t : (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
.
Equations
- s.sigma t = s.bind fun (a : α) => Multiset.map (Sigma.mk a) (t a)
Instances For
@[simp]
theorem
Multiset.zero_sigma
{α : Type u_1}
{σ : α → Type u_4}
(t : (a : α) → Multiset (σ a))
:
Multiset.sigma 0 t = 0
@[simp]
theorem
Multiset.sigma_singleton
{α : Type u_1}
{β : Type v}
(a : α)
(b : α → β)
:
({a}.sigma fun (a : α) => {b a}) = {⟨a, b a⟩}