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 #
@[simp]
theorem
Multiset.card_join
{α : Type u_1}
(S : Multiset (Multiset α))
:
S.join.card = (Multiset.map Multiset.card S).sum
@[simp]
theorem
Multiset.map_join
{α : Type u_1}
{β : Type v}
(f : α → β)
(S : Multiset (Multiset α))
:
Multiset.map f S.join = (Multiset.map (Multiset.map f) S).join
@[simp]
theorem
Multiset.prod_join
{α : Type u_1}
[CommMonoid α]
{S : Multiset (Multiset α)}
:
S.join.prod = (Multiset.map Multiset.prod S).prod
@[simp]
theorem
Multiset.sum_join
{α : Type u_1}
[AddCommMonoid α]
{S : Multiset (Multiset α)}
:
S.join.sum = (Multiset.map Multiset.sum S).sum
theorem
Multiset.rel_join
{α : Type u_1}
{β : Type v}
{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]
@[simp]
theorem
Multiset.bind_cons
{α : 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
@[simp]
theorem
Multiset.bind_singleton
{α : Type u_1}
{β : Type v}
(s : Multiset α)
(f : α → β)
:
(s.bind fun (x : α) => {f x}) = Multiset.map f s
@[simp]
theorem
Multiset.card_bind
{α : Type u_1}
{β : Type v}
(s : Multiset α)
(f : α → Multiset β)
:
(s.bind f).card = (Multiset.map (Multiset.card ∘ f) s).sum
theorem
Multiset.map_bind
{α : 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
{α : 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_map_comm
{α : 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
@[simp]
theorem
Multiset.prod_bind
{α : Type u_1}
{β : Type v}
[CommMonoid β]
(s : Multiset α)
(t : α → Multiset β)
:
(s.bind t).prod = (Multiset.map (fun (a : α) => (t a).prod) s).prod
@[simp]
theorem
Multiset.sum_bind
{α : Type u_1}
{β : Type v}
[AddCommMonoid β]
(s : Multiset α)
(t : α → Multiset β)
:
(s.bind t).sum = (Multiset.map (fun (a : α) => (t a).sum) s).sum
theorem
Multiset.rel_bind
{α : Type u_1}
{β : Type v}
{γ : Type u_2}
{δ : Type u_3}
{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 v}
[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
{α : Type u_1}
{β : Type v}
[DecidableEq α]
{m : Multiset β}
{f : β → Multiset α}
{a : α}
:
Multiset.count a (m.bind f) = (Multiset.map (fun (b : β) => Multiset.count a (f b)) m).sum
@[simp]
theorem
Multiset.nodup_bind
{α : Type u_1}
{β : Type v}
{s : Multiset α}
{f : α → Multiset β}
:
(s.bind f).Nodup ↔ (∀ a ∈ s, (f a).Nodup) ∧ Multiset.Pairwise (Disjoint on f) s
@[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 #
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⟩}
@[simp]
theorem
Multiset.card_sigma
{α : 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