Sums and products over multisets #
In this file we define products and sums indexed by multisets. This is later used to define products and sums indexed by finite sets.
Main declarations #
Multiset.prod
:s.prod f
is the product off i
over alli ∈ s
. Not to be mistaken with the cartesian productMultiset.product
.Multiset.sum
:s.sum f
is the sum off i
over alli ∈ s
.
Product of a multiset given a commutative monoid structure on α
.
prod {a, b, c} = a * b * c
Equations
- Multiset.prod = Multiset.foldr (fun (x1 x2 : α) => x1 * x2) 1
Instances For
Sum of a multiset given a commutative additive monoid structure on α
.
sum {a, b, c} = a + b + c
Equations
- Multiset.sum = Multiset.foldr (fun (x1 x2 : α) => x1 + x2) 0
Instances For
theorem
Multiset.prod_eq_foldr
{α : Type u_3}
[CommMonoid α]
(s : Multiset α)
:
s.prod = Multiset.foldr (fun (x1 x2 : α) => x1 * x2) 1 s
theorem
Multiset.sum_eq_foldr
{α : Type u_3}
[AddCommMonoid α]
(s : Multiset α)
:
s.sum = Multiset.foldr (fun (x1 x2 : α) => x1 + x2) 0 s
theorem
Multiset.prod_eq_foldl
{α : Type u_3}
[CommMonoid α]
(s : Multiset α)
:
s.prod = Multiset.foldl (fun (x1 x2 : α) => x1 * x2) 1 s
theorem
Multiset.sum_eq_foldl
{α : Type u_3}
[AddCommMonoid α]
(s : Multiset α)
:
s.sum = Multiset.foldl (fun (x1 x2 : α) => x1 + x2) 0 s
@[simp]
@[simp]
@[simp]
@[simp]
@[simp]
@[simp]
@[simp]
theorem
Multiset.prod_replicate
{α : Type u_3}
[CommMonoid α]
(n : ℕ)
(a : α)
:
(Multiset.replicate n a).prod = a ^ n
@[simp]
theorem
Multiset.sum_replicate
{α : Type u_3}
[AddCommMonoid α]
(n : ℕ)
(a : α)
:
(Multiset.replicate n a).sum = n • a
theorem
Multiset.pow_count
{α : Type u_3}
[CommMonoid α]
{s : Multiset α}
[DecidableEq α]
(a : α)
:
a ^ Multiset.count a s = (Multiset.filter (Eq a) s).prod
theorem
Multiset.nsmul_count
{α : Type u_3}
[AddCommMonoid α]
{s : Multiset α}
[DecidableEq α]
(a : α)
:
Multiset.count a s • a = (Multiset.filter (Eq a) s).sum
theorem
Multiset.prod_hom_rel
{ι : Type u_2}
{α : Type u_3}
{β : Type u_4}
[CommMonoid α]
[CommMonoid β]
(s : Multiset ι)
{r : α → β → Prop}
{f : ι → α}
{g : ι → β}
(h₁ : r 1 1)
(h₂ : ∀ ⦃a : ι⦄ ⦃b : α⦄ ⦃c : β⦄, r b c → r (f a * b) (g a * c))
:
r (Multiset.map f s).prod (Multiset.map g s).prod
theorem
Multiset.sum_hom_rel
{ι : Type u_2}
{α : Type u_3}
{β : Type u_4}
[AddCommMonoid α]
[AddCommMonoid β]
(s : Multiset ι)
{r : α → β → Prop}
{f : ι → α}
{g : ι → β}
(h₁ : r 0 0)
(h₂ : ∀ ⦃a : ι⦄ ⦃b : α⦄ ⦃c : β⦄, r b c → r (f a + b) (g a + c))
:
r (Multiset.map f s).sum (Multiset.map g s).sum
theorem
Multiset.prod_map_one
{ι : Type u_2}
{α : Type u_3}
[CommMonoid α]
{m : Multiset ι}
:
(Multiset.map (fun (x : ι) => 1) m).prod = 1
theorem
Multiset.sum_map_zero
{ι : Type u_2}
{α : Type u_3}
[AddCommMonoid α]
{m : Multiset ι}
:
(Multiset.map (fun (x : ι) => 0) m).sum = 0
theorem
Multiset.prod_induction
{α : Type u_3}
[CommMonoid α]
(p : α → Prop)
(s : Multiset α)
(p_mul : ∀ (a b : α), p a → p b → p (a * b))
(p_one : p 1)
(p_s : ∀ a ∈ s, p a)
:
p s.prod
theorem
Multiset.sum_induction
{α : Type u_3}
[AddCommMonoid α]
(p : α → Prop)
(s : Multiset α)
(p_mul : ∀ (a b : α), p a → p b → p (a + b))
(p_one : p 0)
(p_s : ∀ a ∈ s, p a)
:
p s.sum
theorem
Multiset.prod_induction_nonempty
{α : Type u_3}
[CommMonoid α]
{s : Multiset α}
(p : α → Prop)
(p_mul : ∀ (a b : α), p a → p b → p (a * b))
(hs : s ≠ ∅)
(p_s : ∀ a ∈ s, p a)
:
p s.prod
theorem
Multiset.sum_induction_nonempty
{α : Type u_3}
[AddCommMonoid α]
{s : Multiset α}
(p : α → Prop)
(p_mul : ∀ (a b : α), p a → p b → p (a + b))
(hs : s ≠ ∅)
(p_s : ∀ a ∈ s, p a)
:
p s.sum