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 of f i over all i ∈ s. Not to be mistaken with the cartesian product Multiset.product.
• Multiset.sum: s.sum f is the sum of f i over all i ∈ s.

Implementation notes #

Nov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports (data.list.big_operators.lemmas rather than .basic) have been moved to a separate file, algebra.big_operators.multiset.lemmas. This split does not need to be permanent.

theorem Multiset.sum.proof_1 {α : Type u_1} [] (x : α) (y : α) (z : α) :
x + (y + z) = y + (x + z)
def Multiset.sum {α : Type u_2} [] :
α

Sum of a multiset given a commutative additive monoid structure on α. sum {a, b, c} = a + b + c

Equations
Instances For
def Multiset.prod {α : Type u_2} [] :
α

Product of a multiset given a commutative monoid structure on α. prod {a, b, c} = a * b * c

Equations
Instances For
theorem Multiset.sum_eq_foldr {α : Type u_2} [] (s : ) :
= Multiset.foldr (fun (x x_1 : α) => x + x_1) 0 s
theorem Multiset.prod_eq_foldr {α : Type u_2} [] (s : ) :
= Multiset.foldr (fun (x x_1 : α) => x * x_1) 1 s
theorem Multiset.sum_eq_foldl {α : Type u_2} [] (s : ) :
= Multiset.foldl (fun (x x_1 : α) => x + x_1) 0 s
theorem Multiset.prod_eq_foldl {α : Type u_2} [] (s : ) :
= Multiset.foldl (fun (x x_1 : α) => x * x_1) 1 s
@[simp]
theorem Multiset.sum_coe {α : Type u_2} [] (l : List α) :
@[simp]
theorem Multiset.prod_coe {α : Type u_2} [] (l : List α) :
@[simp]
theorem Multiset.sum_toList {α : Type u_2} [] (s : ) :
@[simp]
theorem Multiset.prod_toList {α : Type u_2} [] (s : ) :
@[simp]
theorem Multiset.sum_zero {α : Type u_2} [] :
@[simp]
theorem Multiset.prod_zero {α : Type u_2} [] :
@[simp]
theorem Multiset.sum_cons {α : Type u_2} [] (a : α) (s : ) :
@[simp]
theorem Multiset.prod_cons {α : Type u_2} [] (a : α) (s : ) :
@[simp]
theorem Multiset.sum_erase {α : Type u_2} [] {s : } {a : α} [] (h : a s) :
a + =
@[simp]
theorem Multiset.prod_erase {α : Type u_2} [] {s : } {a : α} [] (h : a s) :
a * =
@[simp]
theorem Multiset.sum_map_erase {ι : Type u_1} {α : Type u_2} [] {m : } {f : ια} [] {a : ι} (h : a m) :
@[simp]
theorem Multiset.prod_map_erase {ι : Type u_1} {α : Type u_2} [] {m : } {f : ια} [] {a : ι} (h : a m) :
@[simp]
theorem Multiset.sum_singleton {α : Type u_2} [] (a : α) :
@[simp]
theorem Multiset.prod_singleton {α : Type u_2} [] (a : α) :
= a
theorem Multiset.sum_pair {α : Type u_2} [] (a : α) (b : α) :
Multiset.sum {a, b} = a + b
theorem Multiset.prod_pair {α : Type u_2} [] (a : α) (b : α) :
Multiset.prod {a, b} = a * b
@[simp]
theorem Multiset.sum_add {α : Type u_2} [] (s : ) (t : ) :
@[simp]
theorem Multiset.prod_add {α : Type u_2} [] (s : ) (t : ) :
theorem Multiset.sum_nsmul {α : Type u_2} [] (m : ) (n : ) :
abbrev Multiset.sum_nsmul.match_1 (motive : ) :
∀ (x : ), (Unitmotive 0)(∀ (n : ), motive ())motive x
Equations
• =
Instances For
theorem Multiset.prod_nsmul {α : Type u_2} [] (m : ) (n : ) :
@[simp]
theorem Multiset.sum_replicate {α : Type u_2} [] (n : ) (a : α) :
= n a
@[simp]
theorem Multiset.prod_replicate {α : Type u_2} [] (n : ) (a : α) :
= a ^ n
theorem Multiset.sum_map_eq_nsmul_single {ι : Type u_1} {α : Type u_2} [] {m : } {f : ια} [] (i : ι) (hf : ∀ (i' : ι), i' ii' mf i' = 0) :
theorem Multiset.prod_map_eq_pow_single {ι : Type u_1} {α : Type u_2} [] {m : } {f : ια} [] (i : ι) (hf : ∀ (i' : ι), i' ii' mf i' = 1) :
= f i ^
theorem Multiset.sum_eq_nsmul_single {α : Type u_2} [] {s : } [] (a : α) (h : ∀ (a' : α), a' aa' sa' = 0) :
= a
theorem Multiset.prod_eq_pow_single {α : Type u_2} [] {s : } [] (a : α) (h : ∀ (a' : α), a' aa' sa' = 1) :
= a ^
theorem Multiset.sum_eq_zero {α : Type u_2} [] {s : } (h : xs, x = 0) :
theorem Multiset.prod_eq_one {α : Type u_2} [] {s : } (h : xs, x = 1) :
theorem Multiset.nsmul_count {α : Type u_2} [] {s : } [] (a : α) :
theorem Multiset.pow_count {α : Type u_2} [] {s : } [] (a : α) :
theorem Multiset.sum_hom {α : Type u_2} {β : Type u_3} [] [] (s : ) {F : Type u_5} [FunLike F α β] [] (f : F) :
Multiset.sum (Multiset.map (f) s) = f ()
theorem Multiset.prod_hom {α : Type u_2} {β : Type u_3} [] [] (s : ) {F : Type u_5} [FunLike F α β] [] (f : F) :
Multiset.prod (Multiset.map (f) s) = f ()
theorem Multiset.sum_hom' {ι : Type u_1} {α : Type u_2} {β : Type u_3} [] [] (s : ) {F : Type u_5} [FunLike F α β] [] (f : F) (g : ια) :
Multiset.sum (Multiset.map (fun (i : ι) => f (g i)) s) = f (Multiset.sum ())
theorem Multiset.prod_hom' {ι : Type u_1} {α : Type u_2} {β : Type u_3} [] [] (s : ) {F : Type u_5} [FunLike F α β] [] (f : F) (g : ια) :
Multiset.prod (Multiset.map (fun (i : ι) => f (g i)) s) = f ()
theorem Multiset.sum_hom₂ {ι : Type u_1} {α : Type u_2} {β : Type u_3} {γ : Type u_4} [] [] [] (s : ) (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.sum (Multiset.map (fun (i : ι) => f (f₁ i) (f₂ i)) s) = f (Multiset.sum (Multiset.map f₁ s)) (Multiset.sum (Multiset.map f₂ s))
theorem Multiset.prod_hom₂ {ι : Type u_1} {α : Type u_2} {β : Type u_3} {γ : Type u_4} [] [] [] (s : ) (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.prod (Multiset.map (fun (i : ι) => f (f₁ i) (f₂ i)) s) = f (Multiset.prod (Multiset.map f₁ s)) (Multiset.prod (Multiset.map f₂ s))
theorem Multiset.sum_hom_rel {ι : Type u_1} {α : Type u_2} {β : Type u_3} [] [] (s : ) {r : αβProp} {f : ια} {g : ιβ} (h₁ : r 0 0) (h₂ : ∀ ⦃a : ι⦄ ⦃b : α⦄ ⦃c : β⦄, r b cr (f a + b) (g a + c)) :
theorem Multiset.prod_hom_rel {ι : Type u_1} {α : Type u_2} {β : Type u_3} [] [] (s : ) {r : αβProp} {f : ια} {g : ιβ} (h₁ : r 1 1) (h₂ : ∀ ⦃a : ι⦄ ⦃b : α⦄ ⦃c : β⦄, r b cr (f a * b) (g a * c)) :
r () ()
theorem Multiset.sum_map_zero {ι : Type u_1} {α : Type u_2} [] {m : } :
Multiset.sum (Multiset.map (fun (x : ι) => 0) m) = 0
theorem Multiset.prod_map_one {ι : Type u_1} {α : Type u_2} [] {m : } :
Multiset.prod (Multiset.map (fun (x : ι) => 1) m) = 1
@[simp]
theorem Multiset.sum_map_add {ι : Type u_1} {α : Type u_2} [] {m : } {f : ια} {g : ια} :
Multiset.sum (Multiset.map (fun (i : ι) => f i + g i) m) = Multiset.sum () + Multiset.sum ()
@[simp]
theorem Multiset.prod_map_mul {ι : Type u_1} {α : Type u_2} [] {m : } {f : ια} {g : ια} :
Multiset.prod (Multiset.map (fun (i : ι) => f i * g i) m) = *
theorem Multiset.sum_map_nsmul {ι : Type u_1} {α : Type u_2} [] {m : } {f : ια} {n : } :
Multiset.sum (Multiset.map (fun (i : ι) => n f i) m) = n Multiset.sum ()
theorem Multiset.prod_map_pow {ι : Type u_1} {α : Type u_2} [] {m : } {f : ια} {n : } :
Multiset.prod (Multiset.map (fun (i : ι) => f i ^ n) m) = ^ n
theorem Multiset.sum_map_sum_map {α : Type u_2} {β : Type u_3} {γ : Type u_4} [] (m : ) (n : ) {f : βγα} :
Multiset.sum (Multiset.map (fun (a : β) => Multiset.sum (Multiset.map (fun (b : γ) => f a b) n)) m) = Multiset.sum (Multiset.map (fun (b : γ) => Multiset.sum (Multiset.map (fun (a : β) => f a b) m)) n)
theorem Multiset.prod_map_prod_map {α : Type u_2} {β : Type u_3} {γ : Type u_4} [] (m : ) (n : ) {f : βγα} :
Multiset.prod (Multiset.map (fun (a : β) => Multiset.prod (Multiset.map (fun (b : γ) => f a b) n)) m) = Multiset.prod (Multiset.map (fun (b : γ) => Multiset.prod (Multiset.map (fun (a : β) => f a b) m)) n)
theorem Multiset.sum_induction {α : Type u_2} [] (p : αProp) (s : ) (p_mul : ∀ (a b : α), p ap bp (a + b)) (p_one : p 0) (p_s : as, p a) :
p ()
theorem Multiset.prod_induction {α : Type u_2} [] (p : αProp) (s : ) (p_mul : ∀ (a b : α), p ap bp (a * b)) (p_one : p 1) (p_s : as, p a) :
p ()
theorem Multiset.sum_induction_nonempty {α : Type u_2} [] {s : } (p : αProp) (p_mul : ∀ (a b : α), p ap bp (a + b)) (hs : s ) (p_s : as, p a) :
p ()
theorem Multiset.prod_induction_nonempty {α : Type u_2} [] {s : } (p : αProp) (p_mul : ∀ (a b : α), p ap bp (a * b)) (hs : s ) (p_s : as, p a) :
p ()
theorem Multiset.prod_dvd_prod_of_le {α : Type u_2} [] {s : } {t : } (h : s t) :
theorem Multiset.prod_dvd_prod_of_dvd {α : Type u_2} {β : Type u_3} [] {S : } (g1 : αβ) (g2 : αβ) (h : aS, g1 a g2 a) :
def Multiset.sumAddMonoidHom {α : Type u_2} [] :
→+ α

Multiset.sum, the sum of the elements of a multiset, promoted to a morphism of AddCommMonoids.

Equations
• Multiset.sumAddMonoidHom = { toZeroHom := { toFun := Multiset.sum, map_zero' := }, map_add' := }
Instances For
@[simp]
theorem Multiset.coe_sumAddMonoidHom {α : Type u_2} [] :
theorem Multiset.sum_map_neg' {α : Type u_2} (m : ) :
theorem Multiset.prod_map_inv' {α : Type u_2} (m : ) :
@[simp]
theorem Multiset.sum_map_neg {ι : Type u_1} {α : Type u_2} {m : } {f : ια} :
Multiset.sum (Multiset.map (fun (i : ι) => -f i) m) = -Multiset.sum ()
@[simp]
theorem Multiset.prod_map_inv {ι : Type u_1} {α : Type u_2} {m : } {f : ια} :
Multiset.prod (Multiset.map (fun (i : ι) => (f i)⁻¹) m) = ()⁻¹
@[simp]
theorem Multiset.sum_map_sub {ι : Type u_1} {α : Type u_2} {m : } {f : ια} {g : ια} :
Multiset.sum (Multiset.map (fun (i : ι) => f i - g i) m) = Multiset.sum () - Multiset.sum ()
@[simp]
theorem Multiset.prod_map_div {ι : Type u_1} {α : Type u_2} {m : } {f : ια} {g : ια} :
Multiset.prod (Multiset.map (fun (i : ι) => f i / g i) m) = /
theorem Multiset.sum_map_zsmul {ι : Type u_1} {α : Type u_2} {m : } {f : ια} {n : } :
Multiset.sum (Multiset.map (fun (i : ι) => n f i) m) = n Multiset.sum ()
theorem Multiset.prod_map_zpow {ι : Type u_1} {α : Type u_2} {m : } {f : ια} {n : } :
Multiset.prod (Multiset.map (fun (i : ι) => f i ^ n) m) = ^ n
theorem Multiset.sum_map_mul_left {ι : Type u_1} {α : Type u_2} {a : α} {s : } {f : ια} :
Multiset.sum (Multiset.map (fun (i : ι) => a * f i) s) = a * Multiset.sum ()
theorem Multiset.sum_map_mul_right {ι : Type u_1} {α : Type u_2} {a : α} {s : } {f : ια} :
Multiset.sum (Multiset.map (fun (i : ι) => f i * a) s) = Multiset.sum () * a
@[simp]
theorem Multiset.sum_map_singleton {α : Type u_2} (s : ) :
Multiset.sum (Multiset.map (fun (a : α) => {a}) s) = s
theorem Multiset.sum_nat_mod (s : ) (n : ) :
= Multiset.sum (Multiset.map (fun (x : ) => x % n) s) % n
theorem Multiset.prod_nat_mod (s : ) (n : ) :
= Multiset.prod (Multiset.map (fun (x : ) => x % n) s) % n
theorem Multiset.sum_int_mod (s : ) (n : ) :
= Multiset.sum (Multiset.map (fun (x : ) => x % n) s) % n
theorem Multiset.prod_int_mod (s : ) (n : ) :
= Multiset.prod (Multiset.map (fun (x : ) => x % n) s) % n
theorem map_multiset_sum {α : Type u_2} {β : Type u_3} [] [] {F : Type u_5} [FunLike F α β] [] (f : F) (s : ) :
f () = Multiset.sum (Multiset.map (f) s)
theorem map_multiset_prod {α : Type u_2} {β : Type u_3} [] [] {F : Type u_5} [FunLike F α β] [] (f : F) (s : ) :
f () = Multiset.prod (Multiset.map (f) s)
theorem AddMonoidHom.map_multiset_sum {α : Type u_2} {β : Type u_3} [] [] (f : α →+ β) (s : ) :
f () = Multiset.sum (Multiset.map (f) s)
theorem MonoidHom.map_multiset_prod {α : Type u_2} {β : Type u_3} [] [] (f : α →* β) (s : ) :
f () = Multiset.prod (Multiset.map (f) s)