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
.
Sum of a multiset given a commutative additive monoid structure on α
.
sum {a, b, c} = a + b + c
Equations
- multiset.sum = multiset.foldr has_add.add multiset.sum._proof_1 0
Product of a multiset given a commutative monoid structure on α
.
prod {a, b, c} = a * b * c
Equations
- multiset.prod = multiset.foldr has_mul.mul multiset.prod._proof_1 1
theorem
multiset.sum_eq_foldr
{α : Type u_2}
[add_comm_monoid α]
(s : multiset α) :
s.sum = multiset.foldr has_add.add _ 0 s
theorem
multiset.prod_eq_foldr
{α : Type u_2}
[comm_monoid α]
(s : multiset α) :
s.prod = multiset.foldr has_mul.mul _ 1 s
theorem
multiset.prod_eq_foldl
{α : Type u_2}
[comm_monoid α]
(s : multiset α) :
s.prod = multiset.foldl has_mul.mul _ 1 s
theorem
multiset.sum_eq_foldl
{α : Type u_2}
[add_comm_monoid α]
(s : multiset α) :
s.sum = multiset.foldl has_add.add _ 0 s
@[simp, norm_cast]
@[simp, norm_cast]
@[simp]
@[simp]
@[simp]
@[simp]
@[simp]
@[simp]
@[simp]
@[simp]
@[simp]
theorem
multiset.prod_repeat
{α : Type u_2}
[comm_monoid α]
(a : α)
(n : ℕ) :
(multiset.repeat a n).prod = a ^ n
@[simp]
theorem
multiset.sum_repeat
{α : Type u_2}
[add_comm_monoid α]
(a : α)
(n : ℕ) :
(multiset.repeat a n).sum = n • a
theorem
multiset.pow_count
{α : Type u_2}
[comm_monoid α]
{s : multiset α}
[decidable_eq α]
(a : α) :
a ^ multiset.count a s = (multiset.filter (eq a) s).prod
theorem
multiset.nsmul_count
{α : Type u_2}
[add_comm_monoid α]
{s : multiset α}
[decidable_eq α]
(a : α) :
multiset.count a s • a = (multiset.filter (eq a) s).sum
theorem
multiset.sum_hom
{α : Type u_2}
{β : Type u_3}
[add_comm_monoid α]
[add_comm_monoid β]
(s : multiset α)
{F : Type u_1}
[add_monoid_hom_class F α β]
(f : F) :
theorem
multiset.prod_hom
{α : Type u_2}
{β : Type u_3}
[comm_monoid α]
[comm_monoid β]
(s : multiset α)
{F : Type u_1}
[monoid_hom_class F α β]
(f : F) :
theorem
multiset.sum_hom'
{ι : Type u_1}
{α : Type u_2}
{β : Type u_3}
[add_comm_monoid α]
[add_comm_monoid β]
(s : multiset ι)
{F : Type u_4}
[add_monoid_hom_class F α β]
(f : F)
(g : ι → α) :
(multiset.map (λ (i : ι), ⇑f (g i)) s).sum = ⇑f (multiset.map g s).sum
theorem
multiset.prod_hom'
{ι : Type u_1}
{α : Type u_2}
{β : Type u_3}
[comm_monoid α]
[comm_monoid β]
(s : multiset ι)
{F : Type u_4}
[monoid_hom_class F α β]
(f : F)
(g : ι → α) :
(multiset.map (λ (i : ι), ⇑f (g i)) s).prod = ⇑f (multiset.map g s).prod
theorem
multiset.prod_hom₂
{ι : Type u_1}
{α : Type u_2}
{β : Type u_3}
{γ : Type u_4}
[comm_monoid α]
[comm_monoid β]
[comm_monoid γ]
(s : multiset ι)
(f : α → β → γ)
(hf : ∀ (a b : α) (c d : β), f (a * b) (c * d) = (f a c) * f b d)
(hf' : f 1 1 = 1)
(f₁ : ι → α)
(f₂ : ι → β) :
(multiset.map (λ (i : ι), f (f₁ i) (f₂ i)) s).prod = f (multiset.map f₁ s).prod (multiset.map f₂ s).prod
theorem
multiset.sum_hom₂
{ι : Type u_1}
{α : Type u_2}
{β : Type u_3}
{γ : Type u_4}
[add_comm_monoid α]
[add_comm_monoid β]
[add_comm_monoid γ]
(s : multiset ι)
(f : α → β → γ)
(hf : ∀ (a b : α) (c d : β), f (a + b) (c + d) = f a c + f b d)
(hf' : f 0 0 = 0)
(f₁ : ι → α)
(f₂ : ι → β) :
(multiset.map (λ (i : ι), f (f₁ i) (f₂ i)) s).sum = f (multiset.map f₁ s).sum (multiset.map f₂ s).sum
theorem
multiset.sum_hom_rel
{ι : Type u_1}
{α : Type u_2}
{β : Type u_3}
[add_comm_monoid α]
[add_comm_monoid β]
(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_hom_rel
{ι : Type u_1}
{α : Type u_2}
{β : Type u_3}
[comm_monoid α]
[comm_monoid β]
(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_map_zero
{ι : Type u_1}
{α : Type u_2}
[add_comm_monoid α]
{m : multiset ι} :
(multiset.map (λ (i : ι), 0) m).sum = 0
theorem
multiset.prod_map_one
{ι : Type u_1}
{α : Type u_2}
[comm_monoid α]
{m : multiset ι} :
(multiset.map (λ (i : ι), 1) m).prod = 1
@[simp]
theorem
multiset.sum_map_add
{ι : Type u_1}
{α : Type u_2}
[add_comm_monoid α]
{m : multiset ι}
{f g : ι → α} :
(multiset.map (λ (i : ι), f i + g i) m).sum = (multiset.map f m).sum + (multiset.map g m).sum
@[simp]
theorem
multiset.prod_map_mul
{ι : Type u_1}
{α : Type u_2}
[comm_monoid α]
{m : multiset ι}
{f g : ι → α} :
(multiset.map (λ (i : ι), (f i) * g i) m).prod = ((multiset.map f m).prod) * (multiset.map g m).prod
theorem
multiset.prod_map_pow
{ι : Type u_1}
{α : Type u_2}
[comm_monoid α]
{m : multiset ι}
{f : ι → α}
{n : ℕ} :
(multiset.map (λ (i : ι), f i ^ n) m).prod = (multiset.map f m).prod ^ n
theorem
multiset.sum_map_nsmul
{ι : Type u_1}
{α : Type u_2}
[add_comm_monoid α]
{m : multiset ι}
{f : ι → α}
{n : ℕ} :
(multiset.map (λ (i : ι), n • f i) m).sum = n • (multiset.map f m).sum
theorem
multiset.prod_map_prod_map
{α : Type u_2}
{β : Type u_3}
{γ : Type u_4}
[comm_monoid α]
(m : multiset β)
(n : multiset γ)
{f : β → γ → α} :
(multiset.map (λ (a : β), (multiset.map (λ (b : γ), f a b) n).prod) m).prod = (multiset.map (λ (b : γ), (multiset.map (λ (a : β), f a b) m).prod) n).prod
theorem
multiset.sum_map_sum_map
{α : Type u_2}
{β : Type u_3}
{γ : Type u_4}
[add_comm_monoid α]
(m : multiset β)
(n : multiset γ)
{f : β → γ → α} :
(multiset.map (λ (a : β), (multiset.map (λ (b : γ), f a b) n).sum) m).sum = (multiset.map (λ (b : γ), (multiset.map (λ (a : β), f a b) m).sum) n).sum
theorem
multiset.prod_induction
{α : Type u_2}
[comm_monoid α]
(p : α → Prop)
(s : multiset α)
(p_mul : ∀ (a b : α), p a → p b → p (a * b))
(p_one : p 1)
(p_s : ∀ (a : α), a ∈ s → p a) :
p s.prod
theorem
multiset.sum_induction
{α : Type u_2}
[add_comm_monoid α]
(p : α → Prop)
(s : multiset α)
(p_mul : ∀ (a b : α), p a → p b → p (a + b))
(p_one : p 0)
(p_s : ∀ (a : α), a ∈ s → p a) :
p s.sum
theorem
multiset.sum_induction_nonempty
{α : Type u_2}
[add_comm_monoid α]
{s : multiset α}
(p : α → Prop)
(p_mul : ∀ (a b : α), p a → p b → p (a + b))
(hs : s ≠ ∅)
(p_s : ∀ (a : α), a ∈ s → p a) :
p s.sum
theorem
multiset.prod_induction_nonempty
{α : Type u_2}
[comm_monoid α]
{s : multiset α}
(p : α → Prop)
(p_mul : ∀ (a b : α), p a → p b → p (a * b))
(hs : s ≠ ∅)
(p_s : ∀ (a : α), a ∈ s → p a) :
p s.prod
theorem
multiset.prod_dvd_prod_of_le
{α : Type u_2}
[comm_monoid α]
{s t : multiset α}
(h : s ≤ t) :
theorem
multiset.prod_dvd_prod_of_dvd
{α : Type u_2}
{β : Type u_3}
[comm_monoid β]
{S : multiset α}
(g1 g2 : α → β)
(h : ∀ (a : α), a ∈ S → g1 a ∣ g2 a) :
(multiset.map g1 S).prod ∣ (multiset.map g2 S).prod
multiset.sum
, the sum of the elements of a multiset, promoted to a morphism of
add_comm_monoid
s.
Equations
- multiset.sum_add_monoid_hom = {to_fun := multiset.sum _inst_1, map_zero' := _, map_add' := _}
@[simp]
theorem
multiset.prod_eq_zero
{α : Type u_2}
[comm_monoid_with_zero α]
{s : multiset α}
(h : 0 ∈ s) :
theorem
multiset.prod_eq_zero_iff
{α : Type u_2}
[comm_monoid_with_zero α]
[no_zero_divisors α]
[nontrivial α]
{s : multiset α} :
theorem
multiset.prod_ne_zero
{α : Type u_2}
[comm_monoid_with_zero α]
[no_zero_divisors α]
[nontrivial α]
{s : multiset α}
(h : 0 ∉ s) :
@[simp]
theorem
multiset.sum_map_neg'
{ι : Type u_1}
{α : Type u_2}
[add_comm_group α]
{m : multiset ι}
{f : ι → α} :
(multiset.map (λ (i : ι), -f i) m).sum = -(multiset.map f m).sum
@[simp]
theorem
multiset.prod_map_inv'
{ι : Type u_1}
{α : Type u_2}
[comm_group α]
{m : multiset ι}
{f : ι → α} :
(multiset.map (λ (i : ι), (f i)⁻¹) m).prod = ((multiset.map f m).prod)⁻¹
@[simp]
theorem
multiset.sum_map_sub
{ι : Type u_1}
{α : Type u_2}
[add_comm_group α]
{m : multiset ι}
{f g : ι → α} :
(multiset.map (λ (i : ι), f i - g i) m).sum = (multiset.map f m).sum - (multiset.map g m).sum
@[simp]
theorem
multiset.prod_map_div
{ι : Type u_1}
{α : Type u_2}
[comm_group α]
{m : multiset ι}
{f g : ι → α} :
(multiset.map (λ (i : ι), f i / g i) m).prod = (multiset.map f m).prod / (multiset.map g m).prod
theorem
multiset.prod_map_zpow
{ι : Type u_1}
{α : Type u_2}
[comm_group α]
{m : multiset ι}
{f : ι → α}
{n : ℤ} :
(multiset.map (λ (i : ι), f i ^ n) m).prod = (multiset.map f m).prod ^ n
theorem
multiset.sum_map_zsmul
{ι : Type u_1}
{α : Type u_2}
[add_comm_group α]
{m : multiset ι}
{f : ι → α}
{n : ℤ} :
(multiset.map (λ (i : ι), n • f i) m).sum = n • (multiset.map f m).sum
@[simp]
@[simp]
theorem
multiset.sum_map_neg
{α : Type u_2}
[add_comm_group α]
(m : multiset α) :
(multiset.map has_neg.neg m).sum = -m.sum
@[simp]
theorem
multiset.prod_map_inv
{α : Type u_2}
[comm_group α]
(m : multiset α) :
(multiset.map has_inv.inv m).prod = (m.prod)⁻¹
@[simp]
theorem
multiset.prod_map_inv₀
{ι : Type u_1}
{α : Type u_2}
[comm_group_with_zero α]
{m : multiset ι}
{f : ι → α} :
(multiset.map (λ (i : ι), (f i)⁻¹) m).prod = ((multiset.map f m).prod)⁻¹
@[simp]
theorem
multiset.prod_map_div₀
{ι : Type u_1}
{α : Type u_2}
[comm_group_with_zero α]
{m : multiset ι}
{f g : ι → α} :
(multiset.map (λ (i : ι), f i / g i) m).prod = (multiset.map f m).prod / (multiset.map g m).prod
theorem
multiset.prod_map_zpow₀
{ι : Type u_1}
{α : Type u_2}
[comm_group_with_zero α]
{m : multiset ι}
{f : ι → α}
{n : ℤ} :
(multiset.map (λ (i : ι), f i ^ n) m).prod = (multiset.map f m).prod ^ n
theorem
commute.multiset_sum_right
{α : Type u_2}
[non_unital_non_assoc_semiring α]
(s : multiset α)
(a : α)
(h : ∀ (b : α), b ∈ s → commute a b) :
theorem
commute.multiset_sum_left
{α : Type u_2}
[non_unital_non_assoc_semiring α]
(s : multiset α)
(b : α)
(h : ∀ (a : α), a ∈ s → commute a b) :
theorem
multiset.sum_map_mul_left
{ι : Type u_1}
{α : Type u_2}
[non_unital_non_assoc_semiring α]
{a : α}
{s : multiset ι}
{f : ι → α} :
(multiset.map (λ (i : ι), a * f i) s).sum = a * (multiset.map f s).sum
theorem
multiset.sum_map_mul_right
{ι : Type u_1}
{α : Type u_2}
[non_unital_non_assoc_semiring α]
{a : α}
{s : multiset ι}
{f : ι → α} :
(multiset.map (λ (i : ι), (f i) * a) s).sum = ((multiset.map f s).sum) * a
Order #
theorem
multiset.prod_le_pow_card
{α : Type u_2}
[ordered_comm_monoid α]
(s : multiset α)
(n : α)
(h : ∀ (x : α), x ∈ s → x ≤ n) :
s.prod ≤ n ^ ⇑multiset.card s
theorem
multiset.sum_le_card_nsmul
{α : Type u_2}
[ordered_add_comm_monoid α]
(s : multiset α)
(n : α)
(h : ∀ (x : α), x ∈ s → x ≤ n) :
s.sum ≤ ⇑multiset.card s • n
theorem
multiset.all_one_of_le_one_le_of_prod_eq_one
{α : Type u_2}
[ordered_comm_monoid α]
{s : multiset α} :
theorem
multiset.all_zero_of_le_zero_le_of_sum_eq_zero
{α : Type u_2}
[ordered_add_comm_monoid α]
{s : multiset α} :
theorem
multiset.sum_le_sum_of_rel_le
{α : Type u_2}
[ordered_add_comm_monoid α]
{s t : multiset α}
(h : multiset.rel has_le.le s t) :
theorem
multiset.prod_le_prod_of_rel_le
{α : Type u_2}
[ordered_comm_monoid α]
{s t : multiset α}
(h : multiset.rel has_le.le s t) :
theorem
multiset.prod_map_le_prod
{α : Type u_2}
[ordered_comm_monoid α]
{s : multiset α}
(f : α → α)
(h : ∀ (x : α), x ∈ s → f x ≤ x) :
(multiset.map f s).prod ≤ s.prod
theorem
multiset.sum_map_le_sum
{α : Type u_2}
[ordered_add_comm_monoid α]
{s : multiset α}
(f : α → α)
(h : ∀ (x : α), x ∈ s → f x ≤ x) :
(multiset.map f s).sum ≤ s.sum
theorem
multiset.sum_le_sum_sum
{α : Type u_2}
[ordered_add_comm_monoid α]
{s : multiset α}
(f : α → α)
(h : ∀ (x : α), x ∈ s → x ≤ f x) :
s.sum ≤ (multiset.map f s).sum
theorem
multiset.prod_le_sum_prod
{α : Type u_2}
[ordered_comm_monoid α]
{s : multiset α}
(f : α → α)
(h : ∀ (x : α), x ∈ s → x ≤ f x) :
s.prod ≤ (multiset.map f s).prod
theorem
multiset.card_nsmul_le_sum
{α : Type u_2}
[ordered_add_comm_monoid α]
{s : multiset α}
{a : α}
(h : ∀ (x : α), x ∈ s → a ≤ x) :
⇑multiset.card s • a ≤ s.sum
theorem
multiset.pow_card_le_prod
{α : Type u_2}
[ordered_comm_monoid α]
{s : multiset α}
{a : α}
(h : ∀ (x : α), x ∈ s → a ≤ x) :
a ^ ⇑multiset.card s ≤ s.prod
theorem
multiset.prod_nonneg
{α : Type u_2}
[ordered_comm_semiring α]
{m : multiset α}
(h : ∀ (a : α), a ∈ m → 0 ≤ a) :
theorem
multiset.sum_eq_zero_iff
{α : Type u_2}
[canonically_ordered_add_monoid α]
{m : multiset α} :
theorem
multiset.le_sum_of_mem
{α : Type u_2}
[canonically_ordered_add_monoid α]
{m : multiset α}
{a : α}
(h : a ∈ m) :
theorem
multiset.le_prod_of_mem
{α : Type u_2}
[canonically_ordered_monoid α]
{m : multiset α}
{a : α}
(h : a ∈ m) :
theorem
multiset.le_sum_of_subadditive_on_pred
{α : Type u_2}
{β : Type u_3}
[add_comm_monoid α]
[ordered_add_comm_monoid β]
(f : α → β)
(p : α → Prop)
(h_one : f 0 = 0)
(hp_one : p 0)
(h_mul : ∀ (a b : α), p a → p b → f (a + b) ≤ f a + f b)
(hp_mul : ∀ (a b : α), p a → p b → p (a + b))
(s : multiset α)
(hps : ∀ (a : α), a ∈ s → p a) :
f s.sum ≤ (multiset.map f s).sum
theorem
multiset.le_prod_of_submultiplicative_on_pred
{α : Type u_2}
{β : Type u_3}
[comm_monoid α]
[ordered_comm_monoid β]
(f : α → β)
(p : α → Prop)
(h_one : f 1 = 1)
(hp_one : p 1)
(h_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ (f a) * f b)
(hp_mul : ∀ (a b : α), p a → p b → p (a * b))
(s : multiset α)
(hps : ∀ (a : α), a ∈ s → p a) :
f s.prod ≤ (multiset.map f s).prod
theorem
multiset.le_prod_of_submultiplicative
{α : Type u_2}
{β : Type u_3}
[comm_monoid α]
[ordered_comm_monoid β]
(f : α → β)
(h_one : f 1 = 1)
(h_mul : ∀ (a b : α), f (a * b) ≤ (f a) * f b)
(s : multiset α) :
f s.prod ≤ (multiset.map f s).prod
theorem
multiset.le_sum_of_subadditive
{α : Type u_2}
{β : Type u_3}
[add_comm_monoid α]
[ordered_add_comm_monoid β]
(f : α → β)
(h_one : f 0 = 0)
(h_mul : ∀ (a b : α), f (a + b) ≤ f a + f b)
(s : multiset α) :
f s.sum ≤ (multiset.map f s).sum
theorem
multiset.le_prod_nonempty_of_submultiplicative_on_pred
{α : Type u_2}
{β : Type u_3}
[comm_monoid α]
[ordered_comm_monoid β]
(f : α → β)
(p : α → Prop)
(h_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ (f a) * f b)
(hp_mul : ∀ (a b : α), p a → p b → p (a * b))
(s : multiset α)
(hs_nonempty : s ≠ ∅)
(hs : ∀ (a : α), a ∈ s → p a) :
f s.prod ≤ (multiset.map f s).prod
theorem
multiset.le_sum_nonempty_of_subadditive_on_pred
{α : Type u_2}
{β : Type u_3}
[add_comm_monoid α]
[ordered_add_comm_monoid β]
(f : α → β)
(p : α → Prop)
(h_mul : ∀ (a b : α), p a → p b → f (a + b) ≤ f a + f b)
(hp_mul : ∀ (a b : α), p a → p b → p (a + b))
(s : multiset α)
(hs_nonempty : s ≠ ∅)
(hs : ∀ (a : α), a ∈ s → p a) :
f s.sum ≤ (multiset.map f s).sum
theorem
multiset.le_sum_nonempty_of_subadditive
{α : Type u_2}
{β : Type u_3}
[add_comm_monoid α]
[ordered_add_comm_monoid β]
(f : α → β)
(h_mul : ∀ (a b : α), f (a + b) ≤ f a + f b)
(s : multiset α)
(hs_nonempty : s ≠ ∅) :
f s.sum ≤ (multiset.map f s).sum
theorem
multiset.le_prod_nonempty_of_submultiplicative
{α : Type u_2}
{β : Type u_3}
[comm_monoid α]
[ordered_comm_monoid β]
(f : α → β)
(h_mul : ∀ (a b : α), f (a * b) ≤ (f a) * f b)
(s : multiset α)
(hs_nonempty : s ≠ ∅) :
f s.prod ≤ (multiset.map f s).prod
@[simp]
theorem
multiset.sum_map_singleton
{α : Type u_2}
(s : multiset α) :
(multiset.map (λ (a : α), {a}) s).sum = s
theorem
multiset.abs_sum_le_sum_abs
{α : Type u_2}
[linear_ordered_add_comm_group α]
{s : multiset α} :
theorem
map_multiset_prod
{α : Type u_2}
{β : Type u_3}
[comm_monoid α]
[comm_monoid β]
{F : Type u_1}
[monoid_hom_class F α β]
(f : F)
(s : multiset α) :
theorem
map_multiset_sum
{α : Type u_2}
{β : Type u_3}
[add_comm_monoid α]
[add_comm_monoid β]
{F : Type u_1}
[add_monoid_hom_class F α β]
(f : F)
(s : multiset α) :
@[protected]
theorem
monoid_hom.map_multiset_prod
{α : Type u_2}
{β : Type u_3}
[comm_monoid α]
[comm_monoid β]
(f : α →* β)
(s : multiset α) :
@[protected]
theorem
add_monoid_hom.map_multiset_sum
{α : Type u_2}
{β : Type u_3}
[add_comm_monoid α]
[add_comm_monoid β]
(f : α →+ β)
(s : multiset α) :