Module docstring
{"# Lemmas about Multiset.sum and Multiset.prod requiring extra algebra imports "}
{"# Lemmas about Multiset.sum and Multiset.prod requiring extra algebra imports "}
Multiset.prod_map_neg
theorem
(s : Multiset α) : (s.map Neg.neg).prod = (-1) ^ card s * s.prod
@[simp] lemma prod_map_neg (s : Multiset α) : (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=
Quotient.inductionOn s (by simp)
Multiset.prod_eq_zero
theorem
(h : (0 : α) ∈ s) : s.prod = 0
lemma prod_eq_zero (h : (0 : α) ∈ s) : s.prod = 0 := by
rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩; simp [hs', Multiset.prod_cons]
Multiset.prod_eq_zero_iff
theorem
: s.prod = 0 ↔ (0 : α) ∈ s
@[simp] lemma prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=
Quotient.inductionOn s fun l ↦ by rw [quot_mk_to_coe, prod_coe]; exact List.prod_eq_zero_iff
Multiset.prod_ne_zero
theorem
(h : (0 : α) ∉ s) : s.prod ≠ 0
lemma prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 := mt prod_eq_zero_iff.1 h
Multiset.sum_map_mul_left
theorem
: sum (s.map fun i ↦ a * f i) = a * sum (s.map f)
lemma sum_map_mul_left : sum (s.map fun i ↦ a * f i) = a * sum (s.map f) :=
Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]
Multiset.sum_map_mul_right
theorem
: sum (s.map fun i ↦ f i * a) = sum (s.map f) * a
lemma sum_map_mul_right : sum (s.map fun i ↦ f i * a) = sum (s.map f) * a :=
Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]
Multiset.dvd_sum
theorem
: (∀ x ∈ s, a ∣ x) → a ∣ s.sum
lemma dvd_sum : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=
Multiset.induction_on s (fun _ ↦ dvd_zero _) fun x s ih h ↦ by
rw [sum_cons]
exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy ↦ h _ <| mem_cons.2 <| Or.inr hy)
Multiset.prod_map_sum
theorem
{s : Multiset (Multiset α)} : prod (s.map sum) = sum ((Sections s).map prod)
lemma prod_map_sum {s : Multiset (Multiset α)} :
prod (s.map sum) = sum ((Sections s).map prod) :=
Multiset.induction_on s (by simp) fun a s ih ↦ by
simp [ih, map_bind, sum_map_mul_left, sum_map_mul_right]
Multiset.prod_map_add
theorem
{s : Multiset ι} {f g : ι → α} :
prod (s.map fun i ↦ f i + g i) = sum ((antidiagonal s).map fun p ↦ (p.1.map f).prod * (p.2.map g).prod)
lemma prod_map_add {s : Multiset ι} {f g : ι → α} :
prod (s.map fun i ↦ f i + g i) =
sum ((antidiagonal s).map fun p ↦ (p.1.map f).prod * (p.2.map g).prod) := by
refine s.induction_on ?_ fun a s ih ↦ ?_
· simp only [map_zero, prod_zero, antidiagonal_zero, map_singleton, mul_one, sum_singleton]
· simp only [map_cons, prod_cons, ih, sum_map_mul_left.symm, add_mul, mul_left_comm (f a),
mul_left_comm (g a), sum_map_add, antidiagonal_cons, Prod.map_fst, Prod.map_snd,
id_eq, map_add, map_map, Function.comp_apply, mul_assoc, sum_add]
exact add_comm _ _
Commute.multiset_sum_right
theorem
(a : α) (h : ∀ b ∈ s, Commute a b) : Commute a s.sum
theorem multiset_sum_right (a : α) (h : ∀ b ∈ s, Commute a b) : Commute a s.sum := by
induction s using Quotient.inductionOn
rw [quot_mk_to_coe, sum_coe]
exact Commute.list_sum_right _ _ h
Commute.multiset_sum_left
theorem
(b : α) (h : ∀ a ∈ s, Commute a b) : Commute s.sum b
theorem multiset_sum_left (b : α) (h : ∀ a ∈ s, Commute a b) : Commute s.sum b :=
((Commute.multiset_sum_right _ _) fun _ ha => (h _ ha).symm).symm