diff --git "a/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_BigOperators_Multiset_Basic.jsonl" "b/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_BigOperators_Multiset_Basic.jsonl" new file mode 100644--- /dev/null +++ "b/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_BigOperators_Multiset_Basic.jsonl" @@ -0,0 +1,147 @@ +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\nx y z : α\n⊢ (fun x x_1 => x * x_1) x ((fun x x_1 => x * x_1) y z) = (fun x x_1 => x * x_1) y ((fun x x_1 => x * x_1) x z)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by ","nextTactic":"simp [mul_left_comm]","declUpToTactic":"/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.39_0.GN79r5lQgRvJg8p","decl":"/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns✝ t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\ns : Multiset α\nx y z : α\n⊢ (fun x x_1 => x * x_1) x ((fun x x_1 => x * x_1) y z) = (fun x x_1 => x * x_1) y ((fun x x_1 => x * x_1) x z)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by ","nextTactic":"simp [mul_left_comm]","declUpToTactic":"@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.49_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns✝ t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\ns : Multiset α\nx y z : α\n⊢ (fun x x_1 => x * x_1) ((fun x x_1 => x * x_1) x y) z = (fun x x_1 => x * x_1) ((fun x x_1 => x * x_1) x z) y","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by ","nextTactic":"simp [mul_right_comm]","declUpToTactic":"@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.56_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns✝ t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\ns : Multiset α\n⊢ foldl (fun x y => y * x) (_ : ∀ (_x _y _z : α), _z * (_y * _x) = _y * (_z * _x)) 1 s =\n foldl (fun x x_1 => x * x_1) (_ : ∀ (x y z : α), x * y * z = x * z * y) 1 s","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by ","nextTactic":"simp [mul_comm]","declUpToTactic":"@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.56_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns✝ t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\ns : Multiset α\n⊢ List.prod (toList s) = prod s","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n ","nextTactic":"conv_rhs => rw [← coe_toList s]","declUpToTactic":"@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.69_0.GN79r5lQgRvJg8p","decl":"@[to_additive (attr "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns✝ t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\ns : Multiset α\n| prod s","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ��} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => ","nextTactic":"rw [← coe_toList s]","declUpToTactic":"@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.69_0.GN79r5lQgRvJg8p","decl":"@[to_additive (attr "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns✝ t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\ns : Multiset α\n| prod s","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => ","nextTactic":"rw [← coe_toList s]","declUpToTactic":"@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.69_0.GN79r5lQgRvJg8p","decl":"@[to_additive (attr "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns✝ t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\ns : Multiset α\n| prod s","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => ","nextTactic":"rw [← coe_toList s]","declUpToTactic":"@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.69_0.GN79r5lQgRvJg8p","decl":"@[to_additive (attr "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns✝ t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\ns : Multiset α\n⊢ List.prod (toList s) = prod ↑(toList s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n ","nextTactic":"rw [coe_prod]","declUpToTactic":"@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.69_0.GN79r5lQgRvJg8p","decl":"@[to_additive (attr "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ns t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\ninst✝ : DecidableEq α\nh : a ∈ s\n⊢ a * prod (erase s a) = prod s","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n ","nextTactic":"rw [← s.coe_toList]","declUpToTactic":"@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.88_0.GN79r5lQgRvJg8p","decl":"@[to_additive (attr "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ns t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\ninst✝ : DecidableEq α\nh : a ∈ s\n⊢ a * prod (erase (↑(toList s)) a) = prod ↑(toList s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n ","nextTactic":"rw [coe_erase]","declUpToTactic":"@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.88_0.GN79r5lQgRvJg8p","decl":"@[to_additive (attr "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ns t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\ninst✝ : DecidableEq α\nh : a ∈ s\n⊢ a * prod ↑(List.erase (toList s) a) = prod ↑(toList s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n ","nextTactic":"rw [coe_prod]","declUpToTactic":"@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.88_0.GN79r5lQgRvJg8p","decl":"@[to_additive (attr "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ns t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\ninst✝ : DecidableEq α\nh : a ∈ s\n⊢ a * List.prod (List.erase (toList s) a) = prod ↑(toList s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n ","nextTactic":"rw [coe_prod]","declUpToTactic":"@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.88_0.GN79r5lQgRvJg8p","decl":"@[to_additive (attr "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ns t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\ninst✝ : DecidableEq α\nh : a ∈ s\n⊢ a * List.prod (List.erase (toList s) a) = List.prod (toList s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n ","nextTactic":"rw [List.prod_erase (mem_toList.2 h)]","declUpToTactic":"@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.88_0.GN79r5lQgRvJg8p","decl":"@[to_additive (attr "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ns t : Multiset α\na✝ : α\nm : Multiset ι\nf g : ι → α\ninst✝ : DecidableEq ι\na : ι\nh : a ∈ m\n⊢ f a * prod (map f (erase m a)) = prod (map f m)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n ","nextTactic":"rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]","declUpToTactic":"@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.98_0.GN79r5lQgRvJg8p","decl":"@[to_additive (attr "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns t : Multiset α\na✝ : α\nm : Multiset ι\nf g : ι → α\na : α\n⊢ prod {a} = a","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n ","nextTactic":"simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]","declUpToTactic":"@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.106_0.GN79r5lQgRvJg8p","decl":"@[to_additive (attr "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns t : Multiset α\na✝ : α\nm : Multiset ι\nf g : ι → α\na b : α\n⊢ prod {a, b} = a * b","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n ","nextTactic":"rw [insert_eq_cons]","declUpToTactic":"@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.112_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns t : Multiset α\na✝ : α\nm : Multiset ι\nf g : ι → α\na b : α\n⊢ prod (a ::ₘ {b}) = a * b","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n ","nextTactic":"rw [prod_cons]","declUpToTactic":"@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.112_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns t : Multiset α\na✝ : α\nm : Multiset ι\nf g : ι → α\na b : α\n⊢ a * prod {b} = a * b","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n ","nextTactic":"rw [prod_singleton]","declUpToTactic":"@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.112_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns✝ t✝ : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\ns t : Multiset α\nl₁ l₂ : List α\n⊢ prod (⟦l₁⟧ + ⟦l₂⟧) = prod ⟦l₁⟧ * prod ⟦l₂⟧","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by ","nextTactic":"simp","declUpToTactic":"@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.120_0.GN79r5lQgRvJg8p","decl":"@[to_additive (attr "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns t : Multiset α\na : α\nm✝ : Multiset ι\nf g : ι → α\nm : Multiset α\n⊢ prod (0 • m) = prod m ^ 0","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n ","nextTactic":"rw [zero_nsmul]","declUpToTactic":"@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.126_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]"} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns t : Multiset α\na : α\nm✝ : Multiset ι\nf g : ι → α\nm : Multiset α\n⊢ prod 0 = prod m ^ 0","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n ","nextTactic":"rw [pow_zero]","declUpToTactic":"@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.126_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]"} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns t : Multiset α\na : α\nm✝ : Multiset ι\nf g : ι → α\nm : Multiset α\n⊢ prod 0 = 1","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n ","nextTactic":"rfl","declUpToTactic":"@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.126_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]"} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns t : Multiset α\na : α\nm✝ : Multiset ι\nf g : ι → α\nm : Multiset α\nn : ℕ\n⊢ prod ((n + 1) • m) = prod m ^ (n + 1)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by ","nextTactic":"rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]","declUpToTactic":"@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.126_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]"} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns t : Multiset α\na✝ : α\nm : Multiset ι\nf g : ι → α\nn : ℕ\na : α\n⊢ prod (replicate n a) = a ^ n","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n ","nextTactic":"simp [replicate, List.prod_replicate]","declUpToTactic":"@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.135_0.GN79r5lQgRvJg8p","decl":"@[to_additive (attr "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ns t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\ninst✝ : DecidableEq ι\ni : ι\nhf : ∀ (i' : ι), i' ≠ i → i' ∈ m → f i' = 1\n⊢ prod (map f m) = f i ^ count i m","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n ","nextTactic":"induction' m using Quotient.inductionOn with l","declUpToTactic":"@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.141_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i "} +{"state":"case h\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ns t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\ninst✝ : DecidableEq ι\ni : ι\nl : List ι\nhf : ∀ (i' : ι), i' ≠ i → i' ∈ ⟦l⟧ → f i' = 1\n⊢ prod (map f ⟦l⟧) = f i ^ count i ⟦l⟧","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n ","nextTactic":"simp [List.prod_map_eq_pow_single i f hf]","declUpToTactic":"@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.141_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ns t : Multiset α\na✝ : α\nm : Multiset ι\nf g : ι → α\ninst✝ : DecidableEq α\na : α\nh : ∀ (a' : α), a' ≠ a → a' ∈ s → a' = 1\n⊢ prod s = a ^ count a s","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n ","nextTactic":"induction' s using Quotient.inductionOn with l","declUpToTactic":"@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.149_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a "} +{"state":"case h\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ns t : Multiset α\na✝ : α\nm : Multiset ι\nf g : ι → α\ninst✝ : DecidableEq α\na : α\nl : List α\nh : ∀ (a' : α), a' ≠ a → a' ∈ ⟦l⟧ → a' = 1\n⊢ prod ⟦l⟧ = a ^ count a ⟦l⟧","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n ","nextTactic":"simp [List.prod_eq_pow_single a h]","declUpToTactic":"@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.149_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ns t : Multiset α\na✝ : α\nm : Multiset ι\nf g : ι → α\ninst✝ : DecidableEq α\na : α\n⊢ a ^ count a s = prod (filter (Eq a) s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n ","nextTactic":"rw [filter_eq]","declUpToTactic":"@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.157_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ns t : Multiset α\na✝ : α\nm : Multiset ι\nf g : ι → α\ninst✝ : DecidableEq α\na : α\n⊢ a ^ count a s = prod (replicate (count a s) a)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n ","nextTactic":"rw [prod_replicate]","declUpToTactic":"@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.157_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝² : CommMonoid α\ns✝ t : Multiset α\na : α\nm : Multiset ι\nf✝ g : ι → α\ninst✝¹ : CommMonoid β\ns : Multiset α\nF : Type u_5\ninst✝ : MonoidHomClass F α β\nf : F\nl : List α\n⊢ prod (map ⇑f ⟦l⟧) = f (prod ⟦l⟧)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by ","nextTactic":"simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]","declUpToTactic":"@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.164_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝² : CommMonoid α\ns✝ t : Multiset α\na : α\nm : Multiset ι\nf✝ g✝ : ι → α\ninst✝¹ : CommMonoid β\ns : Multiset ι\nF : Type u_5\ninst✝ : MonoidHomClass F α β\nf : F\ng : ι → α\n⊢ prod (map (fun i => f (g i)) s) = f (prod (map g s))","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : ��} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n ","nextTactic":"convert (s.map g).prod_hom f","declUpToTactic":"@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.171_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod "} +{"state":"case h.e'_2.h.e'_3\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝² : CommMonoid α\ns✝ t : Multiset α\na : α\nm : Multiset ι\nf✝ g✝ : ι → α\ninst✝¹ : CommMonoid β\ns : Multiset ι\nF : Type u_5\ninst✝ : MonoidHomClass F α β\nf : F\ng : ι → α\n⊢ map (fun i => f (g i)) s = map (⇑f) (map g s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n ","nextTactic":"exact (map_map _ _ _).symm","declUpToTactic":"@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.171_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝² : CommMonoid α\ns✝ t : Multiset α\na : α\nm : Multiset ι\nf✝ g : ι → α\ninst✝¹ : CommMonoid β\ninst✝ : CommMonoid γ\ns : Multiset ι\nf : α → β → γ\nhf : ∀ (a b : α) (c d : β), f (a * b) (c * d) = f a c * f b d\nhf' : f 1 1 = 1\nf₁ : ι → α\nf₂ : ι → β\nl : List ι\n⊢ prod (map (fun i => f (f₁ i) (f₂ i)) ⟦l⟧) = f (prod (map f₁ ⟦l⟧)) (prod (map f₂ ⟦l⟧))","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n ","nextTactic":"simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]","declUpToTactic":"@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.179_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ns✝ t : Multiset α\na : α\nm : Multiset ι\nf✝ g✝ : ι → α\ninst✝ : CommMonoid β\ns : Multiset ι\nr : α → β → Prop\nf : ι → α\ng : ι → β\nh₁ : r 1 1\nh₂ : ∀ ⦃a : ι⦄ ⦃b : α⦄ ⦃c : β⦄, r b c → r (f a * b) (g a * c)\nl : List ι\n⊢ r (prod (map f ⟦l⟧)) (prod (map g ⟦l⟧))","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n ","nextTactic":"simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]","declUpToTactic":"@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.188_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\n⊢ prod (map (fun x => 1) m) = 1","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n ","nextTactic":"rw [map_const']","declUpToTactic":"@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.197_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\n⊢ prod (replicate (card m) 1) = 1","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n ","nextTactic":"rw [prod_replicate]","declUpToTactic":"@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.197_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\n⊢ 1 ^ card m = 1","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n ","nextTactic":"rw [one_pow]","declUpToTactic":"@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.197_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ns✝ t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\ninst✝ : HasDistribNeg α\ns : Multiset α\n⊢ ∀ (a : List α), prod (map Neg.neg ⟦a⟧) = (-1) ^ card ⟦a⟧ * prod ⟦a⟧","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by ","nextTactic":"simp","declUpToTactic":"@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.211_0.GN79r5lQgRvJg8p","decl":"@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns t : Multiset α\na : α\nm✝ : Multiset ι\nf✝ g : ι → α\nm : Multiset β\nn : Multiset γ\nf : β → γ → α\n⊢ prod (map (fun a => prod (map (fun b => f a b) n)) 0) = prod (map (fun b => prod (map (fun a => f a b) 0)) n)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by ","nextTactic":"simp","declUpToTactic":"@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.223_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns t : Multiset α\na✝ : α\nm✝¹ : Multiset ι\nf✝ g : ι → α\nm✝ : Multiset β\nn : Multiset γ\nf : β → γ → α\na : β\nm : Multiset β\nih : prod (map (fun a => prod (map (fun b => f a b) n)) m) = prod (map (fun b => prod (map (fun a => f a b) m)) n)\n⊢ prod (map (fun a => prod (map (fun b => f a b) n)) (a ::ₘ m)) =\n prod (map (fun b => prod (map (fun a => f a b) (a ::ₘ m))) n)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by ","nextTactic":"simp [ih]","declUpToTactic":"@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.223_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns✝ t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\np : α → Prop\ns : Multiset α\np_mul : ∀ (a b : α), p a → p b → p (a * b)\np_one : p 1\np_s : ∀ a ∈ s, p a\n⊢ p (prod s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n ","nextTactic":"rw [prod_eq_foldr]","declUpToTactic":"@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.231_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns✝ t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\np : α → Prop\ns : Multiset α\np_mul : ∀ (a b : α), p a → p b → p (a * b)\np_one : p 1\np_s : ∀ a ∈ s, p a\n⊢ p (foldr (fun x x_1 => x * x_1) (_ : ∀ (x y z : α), x * (y * z) = y * (x * z)) 1 s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n ","nextTactic":"exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s","declUpToTactic":"@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.231_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns✝ t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\np : α → Prop\ns : Multiset α\np_mul : ∀ (a b : α), p a → p b → p (a * b)\np_one : p 1\np_s : ∀ a ∈ s, p a\nx y z : α\n⊢ (fun x x_1 => x * x_1) x ((fun x x_1 => x * x_1) y z) = (fun x x_1 => x * x_1) y ((fun x x_1 => x * x_1) x z)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by ","nextTactic":"simp [mul_left_comm]","declUpToTactic":"@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.231_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\np : α → Prop\np_mul : ∀ (a b : α), p a → p b → p (a * b)\nhs : s ≠ ∅\np_s : ∀ a ∈ s, p a\n⊢ p (prod s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n ","nextTactic":"induction' s using Multiset.induction_on with a s hsa","declUpToTactic":"@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.239_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod "} +{"state":"case empty\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\np : α → Prop\np_mul : ∀ (a b : α), p a → p b → p (a * b)\nhs : 0 ≠ ∅\np_s : ∀ a ∈ 0, p a\n⊢ p (prod 0)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · ","nextTactic":"simp at hs","declUpToTactic":"@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.239_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod "} +{"state":"case cons\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns✝ t : Multiset α\na✝ : α\nm : Multiset ι\nf g : ι → α\np : α → Prop\np_mul : ∀ (a b : α), p a → p b → p (a * b)\na : α\ns : Multiset α\nhsa : s ≠ ∅ → (∀ a ∈ s, p a) → p (prod s)\nhs : a ::ₘ s ≠ ∅\np_s : ∀ a_1 ∈ a ::ₘ s, p a_1\n⊢ p (prod (a ::ₘ s))","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n ","nextTactic":"rw [prod_cons]","declUpToTactic":"@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.239_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod "} +{"state":"case cons\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns✝ t : Multiset α\na✝ : α\nm : Multiset ι\nf g : ι → α\np : α → Prop\np_mul : ∀ (a b : α), p a → p b → p (a * b)\na : α\ns : Multiset α\nhsa : s ≠ ∅ → (∀ a ∈ s, p a) → p (prod s)\nhs : a ::ₘ s ≠ ∅\np_s : ∀ a_1 ∈ a ::ₘ s, p a_1\n⊢ p (a * prod s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n ","nextTactic":"by_cases hs_empty : s = ∅","declUpToTactic":"@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.239_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod "} +{"state":"case pos\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns✝ t : Multiset α\na✝ : α\nm : Multiset ι\nf g : ι → α\np : α → Prop\np_mul : ∀ (a b : α), p a → p b → p (a * b)\na : α\ns : Multiset α\nhsa : s ≠ ∅ → (∀ a ∈ s, p a) → p (prod s)\nhs : a ::ₘ s ≠ ∅\np_s : ∀ a_1 ∈ a ::ₘ s, p a_1\nhs_empty : s = ∅\n⊢ p (a * prod s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · ","nextTactic":"simp [hs_empty, p_s a]","declUpToTactic":"@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.239_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod "} +{"state":"case neg\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns✝ t : Multiset α\na✝ : α\nm : Multiset ι\nf g : ι → α\np : α → Prop\np_mul : ∀ (a b : α), p a → p b → p (a * b)\na : α\ns : Multiset α\nhsa : s ≠ ∅ → (∀ a ∈ s, p a) → p (prod s)\nhs : a ::ₘ s ≠ ∅\np_s : ∀ a_1 ∈ a ::ₘ s, p a_1\nhs_empty : ¬s = ∅\n⊢ p (a * prod s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n ","nextTactic":"have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)","declUpToTactic":"@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.239_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod "} +{"state":"case neg\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns✝ t : Multiset α\na✝ : α\nm : Multiset ι\nf g : ι → α\np : α → Prop\np_mul : ∀ (a b : α), p a → p b → p (a * b)\na : α\ns : Multiset α\nhsa : s ≠ ∅ → (∀ a ∈ s, p a) → p (prod s)\nhs : a ::ₘ s ≠ ∅\np_s : ∀ a_1 ∈ a ::ₘ s, p a_1\nhs_empty : ¬s = ∅\nhps : ∀ x ∈ s, p x\n⊢ p (a * prod s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n ","nextTactic":"exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)","declUpToTactic":"@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.239_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns t : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\nh : s ≤ t\n⊢ prod s ∣ prod t","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : �� → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n ","nextTactic":"obtain ⟨z, rfl⟩ := exists_add_of_le h","declUpToTactic":"theorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.253_0.GN79r5lQgRvJg8p","decl":"theorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod "} +{"state":"case intro\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\ns : Multiset α\na : α\nm : Multiset ι\nf g : ι → α\nz : Multiset α\nh : s ≤ s + z\n⊢ prod s ∣ prod (s + z)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n ","nextTactic":"simp only [prod_add, dvd_mul_right]","declUpToTactic":"theorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.253_0.GN79r5lQgRvJg8p","decl":"theorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid β\nS : Multiset α\ng1 g2 : α → β\nh : ∀ a ∈ S, g1 a ∣ g2 a\n⊢ prod (map g1 S) ∣ prod (map g2 S)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n ","nextTactic":"apply Multiset.induction_on' S","declUpToTactic":"theorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.260_0.GN79r5lQgRvJg8p","decl":"theorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod "} +{"state":"case h₁\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid β\nS : Multiset α\ng1 g2 : α → β\nh : ∀ a ∈ S, g1 a ∣ g2 a\n⊢ prod (map g1 0) ∣ prod (map g2 0)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · ","nextTactic":"simp","declUpToTactic":"theorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.260_0.GN79r5lQgRvJg8p","decl":"theorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod "} +{"state":"case h₂\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid β\nS : Multiset α\ng1 g2 : α → β\nh : ∀ a ∈ S, g1 a ∣ g2 a\n⊢ ∀ {a : α} {s : Multiset α},\n a ∈ S → s ⊆ S → prod (map g1 s) ∣ prod (map g2 s) → prod (map g1 (insert a s)) ∣ prod (map g2 (insert a s))","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n ","nextTactic":"intro a T haS _ IH","declUpToTactic":"theorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.260_0.GN79r5lQgRvJg8p","decl":"theorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod "} +{"state":"case h₂\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid β\nS : Multiset α\ng1 g2 : α → β\nh : ∀ a ∈ S, g1 a ∣ g2 a\na : α\nT : Multiset α\nhaS : a ∈ S\na✝ : T ⊆ S\nIH : prod (map g1 T) ∣ prod (map g2 T)\n⊢ prod (map g1 (insert a T)) ∣ prod (map g2 (insert a T))","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n ","nextTactic":"simp [mul_dvd_mul (h a haS) IH]","declUpToTactic":"theorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.260_0.GN79r5lQgRvJg8p","decl":"theorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoidWithZero α\ns : Multiset α\nh : 0 ∈ s\n⊢ prod s = 0","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n ","nextTactic":"rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩","declUpToTactic":"theorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.291_0.GN79r5lQgRvJg8p","decl":"theorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 "} +{"state":"case intro\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoidWithZero α\ns : Multiset α\nh : 0 ∈ s\ns' : Multiset α\nhs' : s = 0 ::ₘ s'\n⊢ prod s = 0","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n ","nextTactic":"simp [hs', Multiset.prod_cons]","declUpToTactic":"theorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.291_0.GN79r5lQgRvJg8p","decl":"theorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝² : CommMonoidWithZero α\ninst✝¹ : NoZeroDivisors α\ninst✝ : Nontrivial α\ns : Multiset α\nl : List α\n⊢ prod ⟦l⟧ = 0 ↔ 0 ∈ ⟦l⟧","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n ","nextTactic":"rw [quot_mk_to_coe]","declUpToTactic":"theorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.298_0.GN79r5lQgRvJg8p","decl":"theorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝² : CommMonoidWithZero α\ninst✝¹ : NoZeroDivisors α\ninst✝ : Nontrivial α\ns : Multiset α\nl : List α\n⊢ prod ↑l = 0 ↔ 0 ∈ ↑l","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n ","nextTactic":"rw [coe_prod]","declUpToTactic":"theorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.298_0.GN79r5lQgRvJg8p","decl":"theorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝² : CommMonoidWithZero α\ninst✝¹ : NoZeroDivisors α\ninst✝ : Nontrivial α\ns : Multiset α\nl : List α\n⊢ List.prod l = 0 ↔ 0 ∈ ↑l","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n ","nextTactic":"exact List.prod_eq_zero_iff","declUpToTactic":"theorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.298_0.GN79r5lQgRvJg8p","decl":"theorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : DivisionCommMonoid α\nm : Multiset ι\nf g : ι → α\n⊢ prod (map (fun i => (f i)⁻¹) m) = (prod (map f m))⁻¹","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n ","nextTactic":"simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]","declUpToTactic":"@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.321_0.GN79r5lQgRvJg8p","decl":"@[to_additive (attr "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : DivisionCommMonoid α\nm : Multiset ι\nf g : ι → α\nn : ℤ\n⊢ prod (map (fun i => f i ^ n) m) = prod (map f m) ^ n","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n ","nextTactic":"convert (m.map f).prod_hom (zpowGroupHom n : α →* α)","declUpToTactic":"@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.334_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n "} +{"state":"case h.e'_2.h.e'_3\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : DivisionCommMonoid α\nm : Multiset ι\nf g : ι → α\nn : ℤ\n⊢ map (fun i => f i ^ n) m = map (⇑(zpowGroupHom n)) (map f m)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n ","nextTactic":"simp only [map_map, Function.comp_apply, zpowGroupHom_apply]","declUpToTactic":"@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.334_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : NonUnitalNonAssocSemiring α\na : α\ns : Multiset ι\nf : ι → α\n⊢ sum (map (fun i => a * f i) 0) = a * sum (map f 0)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by ","nextTactic":"simp","declUpToTactic":"theorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.347_0.GN79r5lQgRvJg8p","decl":"theorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : NonUnitalNonAssocSemiring α\na : α\ns✝ : Multiset ι\nf : ι → α\ni : ι\ns : Multiset ι\nih : sum (map (fun i => a * f i) s) = a * sum (map f s)\n⊢ sum (map (fun i => a * f i) (i ::ₘ s)) = a * sum (map f (i ::ₘ s))","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by ","nextTactic":"simp [ih, mul_add]","declUpToTactic":"theorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.347_0.GN79r5lQgRvJg8p","decl":"theorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : NonUnitalNonAssocSemiring α\na : α\ns : Multiset ι\nf : ι → α\n⊢ sum (map (fun i => f i * a) 0) = sum (map f 0) * a","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by ","nextTactic":"simp","declUpToTactic":"theorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.351_0.GN79r5lQgRvJg8p","decl":"theorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : NonUnitalNonAssocSemiring α\na✝ : α\ns✝ : Multiset ι\nf : ι → α\na : ι\ns : Multiset ι\nih : sum (map (fun i => f i * a✝) s) = sum (map f s) * a✝\n⊢ sum (map (fun i => f i * a✝) (a ::ₘ s)) = sum (map f (a ::ₘ s)) * a✝","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by ","nextTactic":"simp [ih, add_mul]","declUpToTactic":"theorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.351_0.GN79r5lQgRvJg8p","decl":"theorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : NonUnitalSemiring α\na : α\ns✝ : Multiset α\nx : α\ns : Multiset α\nih : (∀ x ∈ s, a ∣ x) → a ∣ sum s\nh : ∀ x_1 ∈ x ::ₘ s, a ∣ x_1\n⊢ a ∣ sum (x ::ₘ s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n ","nextTactic":"rw [sum_cons]","declUpToTactic":"theorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.361_0.GN79r5lQgRvJg8p","decl":"theorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : NonUnitalSemiring α\na : α\ns✝ : Multiset α\nx : α\ns : Multiset α\nih : (∀ x ∈ s, a ∣ x) → a ∣ sum s\nh : ∀ x_1 ∈ x ::ₘ s, a ∣ x_1\n⊢ a ∣ x + sum s","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n ","nextTactic":"exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)","declUpToTactic":"theorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.361_0.GN79r5lQgRvJg8p","decl":"theorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommMonoid α\ns t : Multiset α\na : α\nl : List α\nhl : ∀ x ∈ ⟦l⟧, 1 ≤ x\n⊢ 1 ≤ prod ⟦l⟧","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by ","nextTactic":"simpa using List.one_le_prod_of_one_le hl","declUpToTactic":"@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.376_0.GN79r5lQgRvJg8p","decl":"@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommMonoid α\ns t : Multiset α\na : α\nl : List α\nhl : ∀ x ∈ ⟦l⟧, 1 ≤ x\nx : α\nhx : x ∈ ⟦l⟧\n⊢ x ≤ prod ⟦l⟧","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by ","nextTactic":"simpa using List.single_le_prod hl x hx","declUpToTactic":"@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.382_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommMonoid α\ns✝ t : Multiset α\na : α\ns : Multiset α\nn : α\nh : ∀ x ∈ s, x ≤ n\n⊢ prod s ≤ n ^ card s","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n ","nextTactic":"induction s using Quotient.inductionOn","declUpToTactic":"@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.388_0.GN79r5lQgRvJg8p","decl":"@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s "} +{"state":"case h\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommMonoid α\ns t : Multiset α\na n : α\na✝ : List α\nh : ∀ x ∈ ⟦a✝⟧, x ≤ n\n⊢ prod ⟦a✝⟧ ≤ n ^ card ⟦a✝⟧","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (��� x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n ","nextTactic":"simpa using List.prod_le_pow_card _ _ h","declUpToTactic":"@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.388_0.GN79r5lQgRvJg8p","decl":"@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommMonoid α\ns t : Multiset α\na : α\n⊢ ∀ (a : List α), (∀ x ∈ ⟦a⟧, 1 ≤ x) → prod ⟦a⟧ = 1 → ∀ x ∈ ⟦a⟧, x = 1","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n ","nextTactic":"simp only [quot_mk_to_coe, coe_prod, mem_coe]","declUpToTactic":"@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.395_0.GN79r5lQgRvJg8p","decl":"@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommMonoid α\ns t : Multiset α\na : α\n⊢ ∀ (a : List α), (∀ x ∈ a, 1 ≤ x) → List.prod a = 1 → ∀ x ∈ a, x = 1","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n ","nextTactic":"exact fun l => List.all_one_of_le_one_le_of_prod_eq_one","declUpToTactic":"@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.395_0.GN79r5lQgRvJg8p","decl":"@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommMonoid α\ns t : Multiset α\na : α\nh : Rel (fun x x_1 => x ≤ x_1) s t\n⊢ prod s ≤ prod t","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ��� g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n ","nextTactic":"induction' h with _ _ _ _ rh _ rt","declUpToTactic":"@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.404_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod "} +{"state":"case zero\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommMonoid α\ns t : Multiset α\na : α\n⊢ prod 0 ≤ prod 0","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · ","nextTactic":"rfl","declUpToTactic":"@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.404_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod "} +{"state":"case cons\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommMonoid α\ns t : Multiset α\na a✝¹ b✝ : α\nas✝ bs✝ : Multiset α\nrh : a✝¹ ≤ b✝\na✝ : Rel (fun x x_1 => x ≤ x_1) as✝ bs✝\nrt : prod as✝ ≤ prod bs✝\n⊢ prod (a✝¹ ::ₘ as✝) ≤ prod (b✝ ::ₘ bs✝)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · ","nextTactic":"rw [prod_cons, prod_cons]","declUpToTactic":"@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.404_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod "} +{"state":"case cons\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommMonoid α\ns t : Multiset α\na a✝¹ b✝ : α\nas✝ bs✝ : Multiset α\nrh : a✝¹ ≤ b✝\na✝ : Rel (fun x x_1 => x ≤ x_1) as✝ bs✝\nrt : prod as✝ ≤ prod bs✝\n⊢ a✝¹ * prod as✝ ≤ b✝ * prod bs✝","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n ","nextTactic":"exact mul_le_mul' rh rt","declUpToTactic":"@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.404_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommMonoid α\ns t : Multiset α\na : α\nh : ∀ x ∈ s, a ≤ x\n⊢ a ^ card s ≤ prod s","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n ","nextTactic":"rw [← Multiset.prod_replicate]","declUpToTactic":"@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.432_0.GN79r5lQgRvJg8p","decl":"@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommMonoid α\ns t : Multiset α\na : α\nh : ∀ x ∈ s, a ≤ x\n⊢ prod (replicate (card s) a) ≤ prod s","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n ","nextTactic":"rw [← Multiset.map_const]","declUpToTactic":"@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.432_0.GN79r5lQgRvJg8p","decl":"@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommMonoid α\ns t : Multiset α\na : α\nh : ∀ x ∈ s, a ≤ x\n⊢ prod (map (Function.const α a) s) ≤ prod s","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n ","nextTactic":"exact prod_map_le_prod _ h","declUpToTactic":"@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.432_0.GN79r5lQgRvJg8p","decl":"@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCancelCommMonoid α\ns : Multiset ι\nf g : ι → α\nhle : ∀ i ∈ s, f i ≤ g i\nhlt : ∃ i ∈ s, f i < g i\n⊢ prod (map f s) < prod (map g s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n ","nextTactic":"obtain ⟨l⟩ := s","declUpToTactic":"@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.446_0.GN79r5lQgRvJg8p","decl":"@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod "} +{"state":"case mk\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCancelCommMonoid α\ns : Multiset ι\nf g : ι → α\nl : List ι\nhle : ∀ i ∈ Quot.mk Setoid.r l, f i ≤ g i\nhlt : ∃ i ∈ Quot.mk Setoid.r l, f i < g i\n⊢ prod (map f (Quot.mk Setoid.r l)) < prod (map g (Quot.mk Setoid.r l))","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n ","nextTactic":"simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]","declUpToTactic":"@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.446_0.GN79r5lQgRvJg8p","decl":"@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod "} +{"state":"case mk\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCancelCommMonoid α\ns : Multiset ι\nf g : ι → α\nl : List ι\nhle : ∀ i ∈ Quot.mk Setoid.r l, f i ≤ g i\nhlt : ∃ i ∈ Quot.mk Setoid.r l, f i < g i\n⊢ List.prod (List.map f l) < List.prod (List.map g l)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n ","nextTactic":"exact List.prod_lt_prod' f g hle hlt","declUpToTactic":"@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.446_0.GN79r5lQgRvJg8p","decl":"@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst�� : OrderedCancelCommMonoid α\ns : Multiset ι\nf g : ι → α\nhs : s ≠ ∅\nhfg : ∀ i ∈ s, f i < g i\n⊢ prod (map f s) < prod (map g s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n ","nextTactic":"obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs","declUpToTactic":"@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.453_0.GN79r5lQgRvJg8p","decl":"@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod "} +{"state":"case intro\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCancelCommMonoid α\ns : Multiset ι\nf g : ι → α\nhs : s ≠ ∅\nhfg : ∀ i ∈ s, f i < g i\ni : ι\nhi : i ∈ s\n⊢ prod (map f s) < prod (map g s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n ","nextTactic":"exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩","declUpToTactic":"@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.453_0.GN79r5lQgRvJg8p","decl":"@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommSemiring α\nm : Multiset α\nh : ∀ a ∈ m, 0 ≤ a\n⊢ 0 ≤ prod m","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n ","nextTactic":"revert h","declUpToTactic":"theorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.461_0.GN79r5lQgRvJg8p","decl":"theorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommSemiring α\nm : Multiset α\n⊢ (∀ a ∈ m, 0 ≤ a) → 0 ≤ prod m","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n ","nextTactic":"refine' m.induction_on _ _","declUpToTactic":"theorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.461_0.GN79r5lQgRvJg8p","decl":"theorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod "} +{"state":"case refine'_1\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommSemiring α\nm : Multiset α\n⊢ (∀ a ∈ 0, 0 ≤ a) → 0 ≤ prod 0","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · ","nextTactic":"rintro -","declUpToTactic":"theorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.461_0.GN79r5lQgRvJg8p","decl":"theorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod "} +{"state":"case refine'_1\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommSemiring α\nm : Multiset α\n⊢ 0 ≤ prod 0","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n ","nextTactic":"rw [prod_zero]","declUpToTactic":"theorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.461_0.GN79r5lQgRvJg8p","decl":"theorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod "} +{"state":"case refine'_1\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommSemiring α\nm : Multiset α\n⊢ 0 ≤ 1","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n ","nextTactic":"exact zero_le_one","declUpToTactic":"theorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.461_0.GN79r5lQgRvJg8p","decl":"theorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod "} +{"state":"case refine'_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommSemiring α\nm : Multiset α\n⊢ ∀ ⦃a : α⦄ {s : Multiset α}, ((∀ a ∈ s, 0 ≤ a) → 0 ≤ prod s) → (∀ a_2 ∈ a ::ₘ s, 0 ≤ a_2) → 0 ≤ prod (a ::ₘ s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n ","nextTactic":"intro a s hs ih","declUpToTactic":"theorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.461_0.GN79r5lQgRvJg8p","decl":"theorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod "} +{"state":"case refine'_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommSemiring α\nm : Multiset α\na : α\ns : Multiset α\nhs : (∀ a ∈ s, 0 ≤ a) → 0 ≤ prod s\nih : ∀ a_1 ∈ a ::ₘ s, 0 ≤ a_1\n⊢ 0 ≤ prod (a ::ₘ s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n ","nextTactic":"rw [prod_cons]","declUpToTactic":"theorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.461_0.GN79r5lQgRvJg8p","decl":"theorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod "} +{"state":"case refine'_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : OrderedCommSemiring α\nm : Multiset α\na : α\ns : Multiset α\nhs : (∀ a ∈ s, 0 ≤ a) → 0 ≤ prod s\nih : ∀ a_1 ∈ a ::ₘ s, 0 ≤ a_1\n⊢ 0 ≤ a * prod s","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n ","nextTactic":"exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)","declUpToTactic":"theorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.461_0.GN79r5lQgRvJg8p","decl":"theorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\nm : Multiset α\nh : ∀ x ∈ m, x = 1\n⊢ prod m = 1","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n ","nextTactic":"induction' m using Quotient.inductionOn with l","declUpToTactic":"/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.473_0.GN79r5lQgRvJg8p","decl":"/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 "} +{"state":"case h\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CommMonoid α\nl : List α\nh : ∀ x ∈ ⟦l⟧, x = 1\n⊢ prod ⟦l⟧ = 1","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n ","nextTactic":"simp [List.prod_eq_one h]","declUpToTactic":"/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.473_0.GN79r5lQgRvJg8p","decl":"/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CanonicallyOrderedCommMonoid α\nm : Multiset α\na : α\nh : a ∈ m\n⊢ a ≤ prod m","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n ","nextTactic":"obtain ⟨m', rfl⟩ := exists_cons_of_mem h","declUpToTactic":"@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.482_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod "} +{"state":"case intro\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CanonicallyOrderedCommMonoid α\na : α\nm' : Multiset α\nh : a ∈ a ::ₘ m'\n⊢ a ≤ prod (a ::ₘ m')","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n ","nextTactic":"rw [prod_cons]","declUpToTactic":"@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.482_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod "} +{"state":"case intro\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝ : CanonicallyOrderedCommMonoid α\na : α\nm' : Multiset α\nh : a ∈ a ::ₘ m'\n⊢ a ≤ a * prod m'","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n ","nextTactic":"exact _root_.le_mul_right (le_refl a)","declUpToTactic":"@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.482_0.GN79r5lQgRvJg8p","decl":"@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_one : f 1 = 1\nhp_one : p 1\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\ns : Multiset α\nhps : ∀ a ∈ s, p a\n⊢ f (prod s) ≤ prod (map f s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n ","nextTactic":"revert s","declUpToTactic":"@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.491_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_one : f 1 = 1\nhp_one : p 1\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\n⊢ ∀ (s : Multiset α), (∀ a ∈ s, p a) → f (prod s) ≤ prod (map f s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n ","nextTactic":"refine' Multiset.induction _ _","declUpToTactic":"@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.491_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case refine'_1\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_one : f 1 = 1\nhp_one : p 1\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\n⊢ (∀ a ∈ 0, p a) → f (prod 0) ≤ prod (map f 0)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · ","nextTactic":"simp [le_of_eq h_one]","declUpToTactic":"@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.491_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case refine'_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_one : f 1 = 1\nhp_one : p 1\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\n⊢ ∀ ⦃a : α⦄ {s : Multiset α},\n ((∀ a ∈ s, p a) → f (prod s) ≤ prod (map f s)) →\n (∀ a_2 ∈ a ::ₘ s, p a_2) → f (prod (a ::ₘ s)) ≤ prod (map f (a ::ₘ s))","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f�� i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n ","nextTactic":"intro a s hs hpsa","declUpToTactic":"@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.491_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case refine'_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_one : f 1 = 1\nhp_one : p 1\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\na : α\ns : Multiset α\nhs : (∀ a ∈ s, p a) → f (prod s) ≤ prod (map f s)\nhpsa : ∀ a_1 ∈ a ::ₘ s, p a_1\n⊢ f (prod (a ::ₘ s)) ≤ prod (map f (a ::ₘ s))","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n ","nextTactic":"have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)","declUpToTactic":"@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.491_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case refine'_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_one : f 1 = 1\nhp_one : p 1\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\na : α\ns : Multiset α\nhs : (∀ a ∈ s, p a) → f (prod s) ≤ prod (map f s)\nhpsa : ∀ a_1 ∈ a ::ₘ s, p a_1\nhps : ∀ x ∈ s, p x\n⊢ f (prod (a ::ₘ s)) ≤ prod (map f (a ::ₘ s))","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n ","nextTactic":"have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps","declUpToTactic":"@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.491_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case refine'_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_one : f 1 = 1\nhp_one : p 1\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\na : α\ns : Multiset α\nhs : (∀ a ∈ s, p a) → f (prod s) ≤ prod (map f s)\nhpsa : ∀ a_1 ∈ a ::ₘ s, p a_1\nhps : ∀ x ∈ s, p x\nhp_prod : p (prod s)\n⊢ f (prod (a ::ₘ s)) ≤ prod (map f (a ::ₘ s))","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n ","nextTactic":"rw [prod_cons]","declUpToTactic":"@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.491_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case refine'_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_one : f 1 = 1\nhp_one : p 1\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\na : α\ns : Multiset α\nhs : (∀ a ∈ s, p a) → f (prod s) ≤ prod (map f s)\nhpsa : ∀ a_1 ∈ a ::ₘ s, p a_1\nhps : ∀ x ∈ s, p x\nhp_prod : p (prod s)\n⊢ f (a * prod s) ≤ prod (map f (a ::ₘ s))","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n ","nextTactic":"rw [map_cons]","declUpToTactic":"@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.491_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case refine'_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_one : f 1 = 1\nhp_one : p 1\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\na : α\ns : Multiset α\nhs : (∀ a ∈ s, p a) → f (prod s) ≤ prod (map f s)\nhpsa : ∀ a_1 ∈ a ::ₘ s, p a_1\nhps : ∀ x ∈ s, p x\nhp_prod : p (prod s)\n⊢ f (a * prod s) ≤ prod (f a ::ₘ map f s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n ","nextTactic":"rw [prod_cons]","declUpToTactic":"@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.491_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case refine'_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_one : f 1 = 1\nhp_one : p 1\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\na : α\ns : Multiset α\nhs : (∀ a ∈ s, p a) → f (prod s) ≤ prod (map f s)\nhpsa : ∀ a_1 ∈ a ::ₘ s, p a_1\nhps : ∀ x ∈ s, p x\nhp_prod : p (prod s)\n⊢ f (a * prod s) ≤ f a * prod (map f s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n ","nextTactic":"exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)","declUpToTactic":"@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.491_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\nh_one : f 1 = 1\nh_mul : ∀ (a b : α), f (a * b) ≤ f a * f b\ns : Multiset α\n⊢ ∀ (a b : α), (fun x => True) a → (fun x => True) b → (fun x => True) (a * b)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by ","nextTactic":"simp","declUpToTactic":"@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.509_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\nh_one : f 1 = 1\nh_mul : ∀ (a b : α), f (a * b) ≤ f a * f b\ns : Multiset α\n⊢ ∀ a ∈ s, (fun x => True) a","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by ","nextTactic":"simp","declUpToTactic":"@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.509_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\ns : Multiset α\nhs_nonempty : s ≠ ∅\nhs : ∀ a ∈ s, p a\n⊢ f (prod s) ≤ prod (map f s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n ","nextTactic":"revert s","declUpToTactic":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.518_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\n⊢ ∀ (s : Multiset α), s ≠ ∅ → (∀ a ∈ s, p a) → f (prod s) ≤ prod (map f s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n ","nextTactic":"refine' Multiset.induction _ _","declUpToTactic":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.518_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case refine'_1\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\n⊢ 0 ≠ ∅ → (∀ a ∈ 0, p a) → f (prod 0) ≤ prod (map f 0)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · ","nextTactic":"intro h","declUpToTactic":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.518_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case refine'_1\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\nh : 0 ≠ ∅\n⊢ (∀ a ∈ 0, p a) → f (prod 0) ≤ prod (map f 0)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n ","nextTactic":"exfalso","declUpToTactic":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.518_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case refine'_1.h\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\nh : 0 ≠ ∅\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n ","nextTactic":"exact h rfl","declUpToTactic":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.518_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case refine'_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\n⊢ ∀ ⦃a : α⦄ {s : Multiset α},\n (s ≠ ∅ → (∀ a ∈ s, p a) → f (prod s) ≤ prod (map f s)) →\n a ::ₘ s ≠ ∅ → (∀ a_2 ∈ a ::ₘ s, p a_2) → f (prod (a ::ₘ s)) ≤ prod (map f (a ::ₘ s))","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n ","nextTactic":"rintro a s hs - hsa_prop","declUpToTactic":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.518_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case refine'_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\na : α\ns : Multiset α\nhs : s ≠ ∅ → (∀ a ∈ s, p a) → f (prod s) ≤ prod (map f s)\nhsa_prop : ∀ a_1 ∈ a ::ₘ s, p a_1\n⊢ f (prod (a ::ₘ s)) ≤ prod (map f (a ::ₘ s))","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n ","nextTactic":"rw [prod_cons]","declUpToTactic":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.518_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case refine'_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\na : α\ns : Multiset α\nhs : s ≠ ∅ → (∀ a ∈ s, p a) → f (prod s) ≤ prod (map f s)\nhsa_prop : ∀ a_1 ∈ a ::ₘ s, p a_1\n⊢ f (a * prod s) ≤ prod (map f (a ::ₘ s))","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n ","nextTactic":"rw [map_cons]","declUpToTactic":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.518_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case refine'_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\na : α\ns : Multiset α\nhs : s ≠ ∅ → (∀ a ∈ s, p a) → f (prod s) ≤ prod (map f s)\nhsa_prop : ∀ a_1 ∈ a ::ₘ s, p a_1\n⊢ f (a * prod s) ≤ prod (f a ::ₘ map f s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n ","nextTactic":"rw [prod_cons]","declUpToTactic":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.518_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case refine'_2\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\na : α\ns : Multiset α\nhs : s ≠ ∅ → (∀ a ∈ s, p a) → f (prod s) ≤ prod (map f s)\nhsa_prop : ∀ a_1 ∈ a ::ₘ s, p a_1\n⊢ f (a * prod s) ≤ f a * prod (map f s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n ","nextTactic":"by_cases hs_empty : s = ∅","declUpToTactic":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.518_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case pos\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\na : α\ns : Multiset α\nhs : s ≠ ∅ → (∀ a ∈ s, p a) → f (prod s) ≤ prod (map f s)\nhsa_prop : ∀ a_1 ∈ a ::ₘ s, p a_1\nhs_empty : s = ∅\n⊢ f (a * prod s) ≤ f a * prod (map f s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · ","nextTactic":"simp [hs_empty]","declUpToTactic":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.518_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case neg\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\na : α\ns : Multiset α\nhs : s ≠ ∅ → (∀ a ∈ s, p a) → f (prod s) ≤ prod (map f s)\nhsa_prop : ∀ a_1 ∈ a ::ₘ s, p a_1\nhs_empty : ¬s = ∅\n⊢ f (a * prod s) ≤ f a * prod (map f s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n ","nextTactic":"have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)","declUpToTactic":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.518_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case neg\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\na : α\ns : Multiset α\nhs : s ≠ ∅ → (∀ a ∈ s, p a) → f (prod s) ≤ prod (map f s)\nhsa_prop : ∀ a_1 ∈ a ::ₘ s, p a_1\nhs_empty : ¬s = ∅\nhsa_restrict : ∀ x ∈ s, p x\n⊢ f (a * prod s) ≤ f a * prod (map f s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n ","nextTactic":"have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict","declUpToTactic":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.518_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case neg\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\na : α\ns : Multiset α\nhs : s ≠ ∅ → (∀ a ∈ s, p a) → f (prod s) ≤ prod (map f s)\nhsa_prop : ∀ a_1 ∈ a ::ₘ s, p a_1\nhs_empty : ¬s = ∅\nhsa_restrict : ∀ x ∈ s, p x\nhp_sup : p (prod s)\n⊢ f (a * prod s) ≤ f a * prod (map f s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n ","nextTactic":"have hp_a : p a := hsa_prop a (mem_cons_self a s)","declUpToTactic":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.518_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"case neg\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\np : α → Prop\nh_mul : ∀ (a b : α), p a → p b → f (a * b) ≤ f a * f b\nhp_mul : ∀ (a b : α), p a → p b → p (a * b)\na : α\ns : Multiset α\nhs : s ≠ ∅ → (∀ a ∈ s, p a) → f (prod s) ≤ prod (map f s)\nhsa_prop : ∀ a_1 ∈ a ::ₘ s, p a_1\nhs_empty : ¬s = ∅\nhsa_restrict : ∀ x ∈ s, p x\nhp_sup : p (prod s)\nhp_a : p a\n⊢ f (a * prod s) ≤ f a * prod (map f s)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n have hp_a : p a := hsa_prop a (mem_cons_self a s)\n ","nextTactic":"exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)","declUpToTactic":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n have hp_a : p a := hsa_prop a (mem_cons_self a s)\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.518_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\nh_mul : ∀ (a b : α), f (a * b) ≤ f a * f b\ns : Multiset α\nhs_nonempty : s ≠ ∅\n⊢ ∀ (a b : α), (fun x => True) a → (fun x => True) b → f (a * b) ≤ f a * f b","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α �� α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n have hp_a : p a := hsa_prop a (mem_cons_self a s)\n exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)\n#align multiset.le_prod_nonempty_of_submultiplicative_on_pred Multiset.le_prod_nonempty_of_submultiplicative_on_pred\n#align multiset.le_sum_nonempty_of_subadditive_on_pred Multiset.le_sum_nonempty_of_subadditive_on_pred\n\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by ","nextTactic":"simp [h_mul]","declUpToTactic":"@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.541_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\nh_mul : ∀ (a b : α), f (a * b) ≤ f a * f b\ns : Multiset α\nhs_nonempty : s ≠ ∅\n⊢ ∀ (a b : α), (fun x => True) a → (fun x => True) b → (fun x => True) (a * b)","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n have hp_a : p a := hsa_prop a (mem_cons_self a s)\n exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)\n#align multiset.le_prod_nonempty_of_submultiplicative_on_pred Multiset.le_prod_nonempty_of_submultiplicative_on_pred\n#align multiset.le_sum_nonempty_of_subadditive_on_pred Multiset.le_sum_nonempty_of_subadditive_on_pred\n\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by simp [h_mul]) (by ","nextTactic":"simp","declUpToTactic":"@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by simp [h_mul]) (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.541_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ninst✝¹ : CommMonoid α\ninst✝ : OrderedCommMonoid β\nf : α → β\nh_mul : ∀ (a b : α), f (a * b) ≤ f a * f b\ns : Multiset α\nhs_nonempty : s ≠ ∅\n⊢ ∀ a ∈ s, (fun x => True) a","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n have hp_a : p a := hsa_prop a (mem_cons_self a s)\n exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)\n#align multiset.le_prod_nonempty_of_submultiplicative_on_pred Multiset.le_prod_nonempty_of_submultiplicative_on_pred\n#align multiset.le_sum_nonempty_of_subadditive_on_pred Multiset.le_sum_nonempty_of_subadditive_on_pred\n\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by simp [h_mul]) (by simp) s\n hs_nonempty (by ","nextTactic":"simp","declUpToTactic":"@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by simp [h_mul]) (by simp) s\n hs_nonempty (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.541_0.GN79r5lQgRvJg8p","decl":"@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ns : Multiset α\n⊢ sum (map (fun a => {a}) 0) = 0","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n have hp_a : p a := hsa_prop a (mem_cons_self a s)\n exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)\n#align multiset.le_prod_nonempty_of_submultiplicative_on_pred Multiset.le_prod_nonempty_of_submultiplicative_on_pred\n#align multiset.le_sum_nonempty_of_subadditive_on_pred Multiset.le_sum_nonempty_of_subadditive_on_pred\n\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by simp [h_mul]) (by simp) s\n hs_nonempty (by simp)\n#align multiset.le_prod_nonempty_of_submultiplicative Multiset.le_prod_nonempty_of_submultiplicative\n#align multiset.le_sum_nonempty_of_subadditive Multiset.le_sum_nonempty_of_subadditive\n\n@[simp]\ntheorem sum_map_singleton (s : Multiset α) : (s.map fun a => ({a} : Multiset α)).sum = s :=\n Multiset.induction_on s (by ","nextTactic":"simp","declUpToTactic":"@[simp]\ntheorem sum_map_singleton (s : Multiset α) : (s.map fun a => ({a} : Multiset α)).sum = s :=\n Multiset.induction_on s (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.550_0.GN79r5lQgRvJg8p","decl":"@[simp]\ntheorem sum_map_singleton (s : Multiset α) : (s.map fun a => ({a} : Multiset α)).sum = s "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ns : Multiset α\n⊢ ∀ ⦃a : α⦄ {s : Multiset α}, sum (map (fun a => {a}) s) = s → sum (map (fun a => {a}) (a ::ₘ s)) = a ::ₘ s","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n have hp_a : p a := hsa_prop a (mem_cons_self a s)\n exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)\n#align multiset.le_prod_nonempty_of_submultiplicative_on_pred Multiset.le_prod_nonempty_of_submultiplicative_on_pred\n#align multiset.le_sum_nonempty_of_subadditive_on_pred Multiset.le_sum_nonempty_of_subadditive_on_pred\n\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by simp [h_mul]) (by simp) s\n hs_nonempty (by simp)\n#align multiset.le_prod_nonempty_of_submultiplicative Multiset.le_prod_nonempty_of_submultiplicative\n#align multiset.le_sum_nonempty_of_subadditive Multiset.le_sum_nonempty_of_subadditive\n\n@[simp]\ntheorem sum_map_singleton (s : Multiset α) : (s.map fun a => ({a} : Multiset α)).sum = s :=\n Multiset.induction_on s (by simp) (by ","nextTactic":"simp","declUpToTactic":"@[simp]\ntheorem sum_map_singleton (s : Multiset α) : (s.map fun a => ({a} : Multiset α)).sum = s :=\n Multiset.induction_on s (by simp) (by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.550_0.GN79r5lQgRvJg8p","decl":"@[simp]\ntheorem sum_map_singleton (s : Multiset α) : (s.map fun a => ({a} : Multiset α)).sum = s "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ns : Multiset ℕ\nn : ℕ\n⊢ sum s % n = sum (map (fun x => x % n) s) % n","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n have hp_a : p a := hsa_prop a (mem_cons_self a s)\n exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)\n#align multiset.le_prod_nonempty_of_submultiplicative_on_pred Multiset.le_prod_nonempty_of_submultiplicative_on_pred\n#align multiset.le_sum_nonempty_of_subadditive_on_pred Multiset.le_sum_nonempty_of_subadditive_on_pred\n\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by simp [h_mul]) (by simp) s\n hs_nonempty (by simp)\n#align multiset.le_prod_nonempty_of_submultiplicative Multiset.le_prod_nonempty_of_submultiplicative\n#align multiset.le_sum_nonempty_of_subadditive Multiset.le_sum_nonempty_of_subadditive\n\n@[simp]\ntheorem sum_map_singleton (s : Multiset α) : (s.map fun a => ({a} : Multiset α)).sum = s :=\n Multiset.induction_on s (by simp) (by simp)\n#align multiset.sum_map_singleton Multiset.sum_map_singleton\n\ntheorem abs_sum_le_sum_abs [LinearOrderedAddCommGroup α] {s : Multiset α} :\n abs s.sum ≤ (s.map abs).sum :=\n le_sum_of_subadditive _ abs_zero abs_add s\n#align multiset.abs_sum_le_sum_abs Multiset.abs_sum_le_sum_abs\n\ntheorem sum_nat_mod (s : Multiset ℕ) (n : ℕ) : s.sum % n = (s.map (· % n)).sum % n := by\n ","nextTactic":"induction s using Multiset.induction","declUpToTactic":"theorem sum_nat_mod (s : Multiset ℕ) (n : ℕ) : s.sum % n = (s.map (· % n)).sum % n := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.560_0.GN79r5lQgRvJg8p","decl":"theorem sum_nat_mod (s : Multiset ℕ) (n : ℕ) : s.sum % n = (s.map (· % n)).sum % n "} +{"state":"case empty\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\nn : ℕ\n⊢ sum 0 % n = sum (map (fun x => x % n) 0) % n","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n have hp_a : p a := hsa_prop a (mem_cons_self a s)\n exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)\n#align multiset.le_prod_nonempty_of_submultiplicative_on_pred Multiset.le_prod_nonempty_of_submultiplicative_on_pred\n#align multiset.le_sum_nonempty_of_subadditive_on_pred Multiset.le_sum_nonempty_of_subadditive_on_pred\n\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by simp [h_mul]) (by simp) s\n hs_nonempty (by simp)\n#align multiset.le_prod_nonempty_of_submultiplicative Multiset.le_prod_nonempty_of_submultiplicative\n#align multiset.le_sum_nonempty_of_subadditive Multiset.le_sum_nonempty_of_subadditive\n\n@[simp]\ntheorem sum_map_singleton (s : Multiset α) : (s.map fun a => ({a} : Multiset α)).sum = s :=\n Multiset.induction_on s (by simp) (by simp)\n#align multiset.sum_map_singleton Multiset.sum_map_singleton\n\ntheorem abs_sum_le_sum_abs [LinearOrderedAddCommGroup α] {s : Multiset α} :\n abs s.sum ≤ (s.map abs).sum :=\n le_sum_of_subadditive _ abs_zero abs_add s\n#align multiset.abs_sum_le_sum_abs Multiset.abs_sum_le_sum_abs\n\ntheorem sum_nat_mod (s : Multiset ℕ) (n : ℕ) : s.sum % n = (s.map (· % n)).sum % n := by\n induction s using Multiset.induction <;> ","nextTactic":"simp [Nat.add_mod, *]","declUpToTactic":"theorem sum_nat_mod (s : Multiset ℕ) (n : ℕ) : s.sum % n = (s.map (· % n)).sum % n := by\n induction s using Multiset.induction <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.560_0.GN79r5lQgRvJg8p","decl":"theorem sum_nat_mod (s : Multiset ℕ) (n : ℕ) : s.sum % n = (s.map (· % n)).sum % n "} +{"state":"case cons\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\nn a✝¹ : ℕ\ns✝ : Multiset ℕ\na✝ : sum s✝ % n = sum (map (fun x => x % n) s✝) % n\n⊢ sum (a✝¹ ::ₘ s✝) % n = sum (map (fun x => x % n) (a✝¹ ::ₘ s✝)) % n","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n have hp_a : p a := hsa_prop a (mem_cons_self a s)\n exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)\n#align multiset.le_prod_nonempty_of_submultiplicative_on_pred Multiset.le_prod_nonempty_of_submultiplicative_on_pred\n#align multiset.le_sum_nonempty_of_subadditive_on_pred Multiset.le_sum_nonempty_of_subadditive_on_pred\n\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by simp [h_mul]) (by simp) s\n hs_nonempty (by simp)\n#align multiset.le_prod_nonempty_of_submultiplicative Multiset.le_prod_nonempty_of_submultiplicative\n#align multiset.le_sum_nonempty_of_subadditive Multiset.le_sum_nonempty_of_subadditive\n\n@[simp]\ntheorem sum_map_singleton (s : Multiset α) : (s.map fun a => ({a} : Multiset α)).sum = s :=\n Multiset.induction_on s (by simp) (by simp)\n#align multiset.sum_map_singleton Multiset.sum_map_singleton\n\ntheorem abs_sum_le_sum_abs [LinearOrderedAddCommGroup α] {s : Multiset α} :\n abs s.sum ≤ (s.map abs).sum :=\n le_sum_of_subadditive _ abs_zero abs_add s\n#align multiset.abs_sum_le_sum_abs Multiset.abs_sum_le_sum_abs\n\ntheorem sum_nat_mod (s : Multiset ℕ) (n : ℕ) : s.sum % n = (s.map (· % n)).sum % n := by\n induction s using Multiset.induction <;> ","nextTactic":"simp [Nat.add_mod, *]","declUpToTactic":"theorem sum_nat_mod (s : Multiset ℕ) (n : ℕ) : s.sum % n = (s.map (· % n)).sum % n := by\n induction s using Multiset.induction <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.560_0.GN79r5lQgRvJg8p","decl":"theorem sum_nat_mod (s : Multiset ℕ) (n : ℕ) : s.sum % n = (s.map (· % n)).sum % n "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ns : Multiset ℕ\nn : ℕ\n⊢ prod s % n = prod (map (fun x => x % n) s) % n","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n have hp_a : p a := hsa_prop a (mem_cons_self a s)\n exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)\n#align multiset.le_prod_nonempty_of_submultiplicative_on_pred Multiset.le_prod_nonempty_of_submultiplicative_on_pred\n#align multiset.le_sum_nonempty_of_subadditive_on_pred Multiset.le_sum_nonempty_of_subadditive_on_pred\n\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by simp [h_mul]) (by simp) s\n hs_nonempty (by simp)\n#align multiset.le_prod_nonempty_of_submultiplicative Multiset.le_prod_nonempty_of_submultiplicative\n#align multiset.le_sum_nonempty_of_subadditive Multiset.le_sum_nonempty_of_subadditive\n\n@[simp]\ntheorem sum_map_singleton (s : Multiset α) : (s.map fun a => ({a} : Multiset α)).sum = s :=\n Multiset.induction_on s (by simp) (by simp)\n#align multiset.sum_map_singleton Multiset.sum_map_singleton\n\ntheorem abs_sum_le_sum_abs [LinearOrderedAddCommGroup α] {s : Multiset α} :\n abs s.sum ≤ (s.map abs).sum :=\n le_sum_of_subadditive _ abs_zero abs_add s\n#align multiset.abs_sum_le_sum_abs Multiset.abs_sum_le_sum_abs\n\ntheorem sum_nat_mod (s : Multiset ℕ) (n : ℕ) : s.sum % n = (s.map (· % n)).sum % n := by\n induction s using Multiset.induction <;> simp [Nat.add_mod, *]\n#align multiset.sum_nat_mod Multiset.sum_nat_mod\n\ntheorem prod_nat_mod (s : Multiset ℕ) (n : ℕ) : s.prod % n = (s.map (· % n)).prod % n := by\n ","nextTactic":"induction s using Multiset.induction","declUpToTactic":"theorem prod_nat_mod (s : Multiset ℕ) (n : ℕ) : s.prod % n = (s.map (· % n)).prod % n := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.564_0.GN79r5lQgRvJg8p","decl":"theorem prod_nat_mod (s : Multiset ℕ) (n : ℕ) : s.prod % n = (s.map (· % n)).prod % n "} +{"state":"case empty\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\nn : ℕ\n⊢ prod 0 % n = prod (map (fun x => x % n) 0) % n","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n have hp_a : p a := hsa_prop a (mem_cons_self a s)\n exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)\n#align multiset.le_prod_nonempty_of_submultiplicative_on_pred Multiset.le_prod_nonempty_of_submultiplicative_on_pred\n#align multiset.le_sum_nonempty_of_subadditive_on_pred Multiset.le_sum_nonempty_of_subadditive_on_pred\n\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by simp [h_mul]) (by simp) s\n hs_nonempty (by simp)\n#align multiset.le_prod_nonempty_of_submultiplicative Multiset.le_prod_nonempty_of_submultiplicative\n#align multiset.le_sum_nonempty_of_subadditive Multiset.le_sum_nonempty_of_subadditive\n\n@[simp]\ntheorem sum_map_singleton (s : Multiset α) : (s.map fun a => ({a} : Multiset α)).sum = s :=\n Multiset.induction_on s (by simp) (by simp)\n#align multiset.sum_map_singleton Multiset.sum_map_singleton\n\ntheorem abs_sum_le_sum_abs [LinearOrderedAddCommGroup α] {s : Multiset α} :\n abs s.sum ≤ (s.map abs).sum :=\n le_sum_of_subadditive _ abs_zero abs_add s\n#align multiset.abs_sum_le_sum_abs Multiset.abs_sum_le_sum_abs\n\ntheorem sum_nat_mod (s : Multiset ℕ) (n : ℕ) : s.sum % n = (s.map (· % n)).sum % n := by\n induction s using Multiset.induction <;> simp [Nat.add_mod, *]\n#align multiset.sum_nat_mod Multiset.sum_nat_mod\n\ntheorem prod_nat_mod (s : Multiset ℕ) (n : ℕ) : s.prod % n = (s.map (· % n)).prod % n := by\n induction s using Multiset.induction <;> ","nextTactic":"simp [Nat.mul_mod, *]","declUpToTactic":"theorem prod_nat_mod (s : Multiset ℕ) (n : ℕ) : s.prod % n = (s.map (· % n)).prod % n := by\n induction s using Multiset.induction <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.564_0.GN79r5lQgRvJg8p","decl":"theorem prod_nat_mod (s : Multiset ℕ) (n : ℕ) : s.prod % n = (s.map (· % n)).prod % n "} +{"state":"case cons\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\nn a✝¹ : ℕ\ns✝ : Multiset ℕ\na✝ : prod s✝ % n = prod (map (fun x => x % n) s✝) % n\n⊢ prod (a✝¹ ::ₘ s✝) % n = prod (map (fun x => x % n) (a✝¹ ::ₘ s✝)) % n","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n have hp_a : p a := hsa_prop a (mem_cons_self a s)\n exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)\n#align multiset.le_prod_nonempty_of_submultiplicative_on_pred Multiset.le_prod_nonempty_of_submultiplicative_on_pred\n#align multiset.le_sum_nonempty_of_subadditive_on_pred Multiset.le_sum_nonempty_of_subadditive_on_pred\n\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by simp [h_mul]) (by simp) s\n hs_nonempty (by simp)\n#align multiset.le_prod_nonempty_of_submultiplicative Multiset.le_prod_nonempty_of_submultiplicative\n#align multiset.le_sum_nonempty_of_subadditive Multiset.le_sum_nonempty_of_subadditive\n\n@[simp]\ntheorem sum_map_singleton (s : Multiset α) : (s.map fun a => ({a} : Multiset α)).sum = s :=\n Multiset.induction_on s (by simp) (by simp)\n#align multiset.sum_map_singleton Multiset.sum_map_singleton\n\ntheorem abs_sum_le_sum_abs [LinearOrderedAddCommGroup α] {s : Multiset α} :\n abs s.sum ≤ (s.map abs).sum :=\n le_sum_of_subadditive _ abs_zero abs_add s\n#align multiset.abs_sum_le_sum_abs Multiset.abs_sum_le_sum_abs\n\ntheorem sum_nat_mod (s : Multiset ℕ) (n : ℕ) : s.sum % n = (s.map (· % n)).sum % n := by\n induction s using Multiset.induction <;> simp [Nat.add_mod, *]\n#align multiset.sum_nat_mod Multiset.sum_nat_mod\n\ntheorem prod_nat_mod (s : Multiset ℕ) (n : ℕ) : s.prod % n = (s.map (· % n)).prod % n := by\n induction s using Multiset.induction <;> ","nextTactic":"simp [Nat.mul_mod, *]","declUpToTactic":"theorem prod_nat_mod (s : Multiset ℕ) (n : ℕ) : s.prod % n = (s.map (· % n)).prod % n := by\n induction s using Multiset.induction <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.564_0.GN79r5lQgRvJg8p","decl":"theorem prod_nat_mod (s : Multiset ℕ) (n : ℕ) : s.prod % n = (s.map (· % n)).prod % n "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ns : Multiset ℤ\nn : ℤ\n⊢ sum s % n = sum (map (fun x => x % n) s) % n","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n have hp_a : p a := hsa_prop a (mem_cons_self a s)\n exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)\n#align multiset.le_prod_nonempty_of_submultiplicative_on_pred Multiset.le_prod_nonempty_of_submultiplicative_on_pred\n#align multiset.le_sum_nonempty_of_subadditive_on_pred Multiset.le_sum_nonempty_of_subadditive_on_pred\n\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by simp [h_mul]) (by simp) s\n hs_nonempty (by simp)\n#align multiset.le_prod_nonempty_of_submultiplicative Multiset.le_prod_nonempty_of_submultiplicative\n#align multiset.le_sum_nonempty_of_subadditive Multiset.le_sum_nonempty_of_subadditive\n\n@[simp]\ntheorem sum_map_singleton (s : Multiset α) : (s.map fun a => ({a} : Multiset α)).sum = s :=\n Multiset.induction_on s (by simp) (by simp)\n#align multiset.sum_map_singleton Multiset.sum_map_singleton\n\ntheorem abs_sum_le_sum_abs [LinearOrderedAddCommGroup α] {s : Multiset α} :\n abs s.sum ≤ (s.map abs).sum :=\n le_sum_of_subadditive _ abs_zero abs_add s\n#align multiset.abs_sum_le_sum_abs Multiset.abs_sum_le_sum_abs\n\ntheorem sum_nat_mod (s : Multiset ℕ) (n : ℕ) : s.sum % n = (s.map (· % n)).sum % n := by\n induction s using Multiset.induction <;> simp [Nat.add_mod, *]\n#align multiset.sum_nat_mod Multiset.sum_nat_mod\n\ntheorem prod_nat_mod (s : Multiset ℕ) (n : ℕ) : s.prod % n = (s.map (· % n)).prod % n := by\n induction s using Multiset.induction <;> simp [Nat.mul_mod, *]\n#align multiset.prod_nat_mod Multiset.prod_nat_mod\n\ntheorem sum_int_mod (s : Multiset ℤ) (n : ℤ) : s.sum % n = (s.map (· % n)).sum % n := by\n ","nextTactic":"induction s using Multiset.induction","declUpToTactic":"theorem sum_int_mod (s : Multiset ℤ) (n : ℤ) : s.sum % n = (s.map (· % n)).sum % n := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.568_0.GN79r5lQgRvJg8p","decl":"theorem sum_int_mod (s : Multiset ℤ) (n : ℤ) : s.sum % n = (s.map (· % n)).sum % n "} +{"state":"case empty\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\nn : ℤ\n⊢ sum 0 % n = sum (map (fun x => x % n) 0) % n","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n have hp_a : p a := hsa_prop a (mem_cons_self a s)\n exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)\n#align multiset.le_prod_nonempty_of_submultiplicative_on_pred Multiset.le_prod_nonempty_of_submultiplicative_on_pred\n#align multiset.le_sum_nonempty_of_subadditive_on_pred Multiset.le_sum_nonempty_of_subadditive_on_pred\n\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by simp [h_mul]) (by simp) s\n hs_nonempty (by simp)\n#align multiset.le_prod_nonempty_of_submultiplicative Multiset.le_prod_nonempty_of_submultiplicative\n#align multiset.le_sum_nonempty_of_subadditive Multiset.le_sum_nonempty_of_subadditive\n\n@[simp]\ntheorem sum_map_singleton (s : Multiset α) : (s.map fun a => ({a} : Multiset α)).sum = s :=\n Multiset.induction_on s (by simp) (by simp)\n#align multiset.sum_map_singleton Multiset.sum_map_singleton\n\ntheorem abs_sum_le_sum_abs [LinearOrderedAddCommGroup α] {s : Multiset α} :\n abs s.sum ≤ (s.map abs).sum :=\n le_sum_of_subadditive _ abs_zero abs_add s\n#align multiset.abs_sum_le_sum_abs Multiset.abs_sum_le_sum_abs\n\ntheorem sum_nat_mod (s : Multiset ℕ) (n : ℕ) : s.sum % n = (s.map (· % n)).sum % n := by\n induction s using Multiset.induction <;> simp [Nat.add_mod, *]\n#align multiset.sum_nat_mod Multiset.sum_nat_mod\n\ntheorem prod_nat_mod (s : Multiset ℕ) (n : ℕ) : s.prod % n = (s.map (· % n)).prod % n := by\n induction s using Multiset.induction <;> simp [Nat.mul_mod, *]\n#align multiset.prod_nat_mod Multiset.prod_nat_mod\n\ntheorem sum_int_mod (s : Multiset ℤ) (n : ℤ) : s.sum % n = (s.map (· % n)).sum % n := by\n induction s using Multiset.induction <;> ","nextTactic":"simp [Int.add_emod, *]","declUpToTactic":"theorem sum_int_mod (s : Multiset ℤ) (n : ℤ) : s.sum % n = (s.map (· % n)).sum % n := by\n induction s using Multiset.induction <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.568_0.GN79r5lQgRvJg8p","decl":"theorem sum_int_mod (s : Multiset ℤ) (n : ℤ) : s.sum % n = (s.map (· % n)).sum % n "} +{"state":"case cons\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\nn a✝¹ : ℤ\ns✝ : Multiset ℤ\na✝ : sum s✝ % n = sum (map (fun x => x % n) s✝) % n\n⊢ sum (a✝¹ ::ₘ s✝) % n = sum (map (fun x => x % n) (a✝¹ ::ₘ s✝)) % n","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ��} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n have hp_a : p a := hsa_prop a (mem_cons_self a s)\n exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)\n#align multiset.le_prod_nonempty_of_submultiplicative_on_pred Multiset.le_prod_nonempty_of_submultiplicative_on_pred\n#align multiset.le_sum_nonempty_of_subadditive_on_pred Multiset.le_sum_nonempty_of_subadditive_on_pred\n\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by simp [h_mul]) (by simp) s\n hs_nonempty (by simp)\n#align multiset.le_prod_nonempty_of_submultiplicative Multiset.le_prod_nonempty_of_submultiplicative\n#align multiset.le_sum_nonempty_of_subadditive Multiset.le_sum_nonempty_of_subadditive\n\n@[simp]\ntheorem sum_map_singleton (s : Multiset α) : (s.map fun a => ({a} : Multiset α)).sum = s :=\n Multiset.induction_on s (by simp) (by simp)\n#align multiset.sum_map_singleton Multiset.sum_map_singleton\n\ntheorem abs_sum_le_sum_abs [LinearOrderedAddCommGroup α] {s : Multiset α} :\n abs s.sum ≤ (s.map abs).sum :=\n le_sum_of_subadditive _ abs_zero abs_add s\n#align multiset.abs_sum_le_sum_abs Multiset.abs_sum_le_sum_abs\n\ntheorem sum_nat_mod (s : Multiset ℕ) (n : ℕ) : s.sum % n = (s.map (· % n)).sum % n := by\n induction s using Multiset.induction <;> simp [Nat.add_mod, *]\n#align multiset.sum_nat_mod Multiset.sum_nat_mod\n\ntheorem prod_nat_mod (s : Multiset ℕ) (n : ℕ) : s.prod % n = (s.map (· % n)).prod % n := by\n induction s using Multiset.induction <;> simp [Nat.mul_mod, *]\n#align multiset.prod_nat_mod Multiset.prod_nat_mod\n\ntheorem sum_int_mod (s : Multiset ℤ) (n : ℤ) : s.sum % n = (s.map (· % n)).sum % n := by\n induction s using Multiset.induction <;> ","nextTactic":"simp [Int.add_emod, *]","declUpToTactic":"theorem sum_int_mod (s : Multiset ℤ) (n : ℤ) : s.sum % n = (s.map (· % n)).sum % n := by\n induction s using Multiset.induction <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.568_0.GN79r5lQgRvJg8p","decl":"theorem sum_int_mod (s : Multiset ℤ) (n : ℤ) : s.sum % n = (s.map (· % n)).sum % n "} +{"state":"ι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\ns : Multiset ℤ\nn : ℤ\n⊢ prod s % n = prod (map (fun x => x % n) s) % n","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n have hp_a : p a := hsa_prop a (mem_cons_self a s)\n exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)\n#align multiset.le_prod_nonempty_of_submultiplicative_on_pred Multiset.le_prod_nonempty_of_submultiplicative_on_pred\n#align multiset.le_sum_nonempty_of_subadditive_on_pred Multiset.le_sum_nonempty_of_subadditive_on_pred\n\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by simp [h_mul]) (by simp) s\n hs_nonempty (by simp)\n#align multiset.le_prod_nonempty_of_submultiplicative Multiset.le_prod_nonempty_of_submultiplicative\n#align multiset.le_sum_nonempty_of_subadditive Multiset.le_sum_nonempty_of_subadditive\n\n@[simp]\ntheorem sum_map_singleton (s : Multiset α) : (s.map fun a => ({a} : Multiset α)).sum = s :=\n Multiset.induction_on s (by simp) (by simp)\n#align multiset.sum_map_singleton Multiset.sum_map_singleton\n\ntheorem abs_sum_le_sum_abs [LinearOrderedAddCommGroup α] {s : Multiset α} :\n abs s.sum ≤ (s.map abs).sum :=\n le_sum_of_subadditive _ abs_zero abs_add s\n#align multiset.abs_sum_le_sum_abs Multiset.abs_sum_le_sum_abs\n\ntheorem sum_nat_mod (s : Multiset ℕ) (n : ℕ) : s.sum % n = (s.map (· % n)).sum % n := by\n induction s using Multiset.induction <;> simp [Nat.add_mod, *]\n#align multiset.sum_nat_mod Multiset.sum_nat_mod\n\ntheorem prod_nat_mod (s : Multiset ℕ) (n : ℕ) : s.prod % n = (s.map (· % n)).prod % n := by\n induction s using Multiset.induction <;> simp [Nat.mul_mod, *]\n#align multiset.prod_nat_mod Multiset.prod_nat_mod\n\ntheorem sum_int_mod (s : Multiset ℤ) (n : ℤ) : s.sum % n = (s.map (· % n)).sum % n := by\n induction s using Multiset.induction <;> simp [Int.add_emod, *]\n#align multiset.sum_int_mod Multiset.sum_int_mod\n\ntheorem prod_int_mod (s : Multiset ℤ) (n : ℤ) : s.prod % n = (s.map (· % n)).prod % n := by\n ","nextTactic":"induction s using Multiset.induction","declUpToTactic":"theorem prod_int_mod (s : Multiset ℤ) (n : ℤ) : s.prod % n = (s.map (· % n)).prod % n := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.572_0.GN79r5lQgRvJg8p","decl":"theorem prod_int_mod (s : Multiset ℤ) (n : ℤ) : s.prod % n = (s.map (· % n)).prod % n "} +{"state":"case empty\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\nn : ℤ\n⊢ prod 0 % n = prod (map (fun x => x % n) 0) % n","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ��� x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n have hp_a : p a := hsa_prop a (mem_cons_self a s)\n exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)\n#align multiset.le_prod_nonempty_of_submultiplicative_on_pred Multiset.le_prod_nonempty_of_submultiplicative_on_pred\n#align multiset.le_sum_nonempty_of_subadditive_on_pred Multiset.le_sum_nonempty_of_subadditive_on_pred\n\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by simp [h_mul]) (by simp) s\n hs_nonempty (by simp)\n#align multiset.le_prod_nonempty_of_submultiplicative Multiset.le_prod_nonempty_of_submultiplicative\n#align multiset.le_sum_nonempty_of_subadditive Multiset.le_sum_nonempty_of_subadditive\n\n@[simp]\ntheorem sum_map_singleton (s : Multiset α) : (s.map fun a => ({a} : Multiset α)).sum = s :=\n Multiset.induction_on s (by simp) (by simp)\n#align multiset.sum_map_singleton Multiset.sum_map_singleton\n\ntheorem abs_sum_le_sum_abs [LinearOrderedAddCommGroup α] {s : Multiset α} :\n abs s.sum ≤ (s.map abs).sum :=\n le_sum_of_subadditive _ abs_zero abs_add s\n#align multiset.abs_sum_le_sum_abs Multiset.abs_sum_le_sum_abs\n\ntheorem sum_nat_mod (s : Multiset ℕ) (n : ℕ) : s.sum % n = (s.map (· % n)).sum % n := by\n induction s using Multiset.induction <;> simp [Nat.add_mod, *]\n#align multiset.sum_nat_mod Multiset.sum_nat_mod\n\ntheorem prod_nat_mod (s : Multiset ℕ) (n : ℕ) : s.prod % n = (s.map (· % n)).prod % n := by\n induction s using Multiset.induction <;> simp [Nat.mul_mod, *]\n#align multiset.prod_nat_mod Multiset.prod_nat_mod\n\ntheorem sum_int_mod (s : Multiset ℤ) (n : ℤ) : s.sum % n = (s.map (· % n)).sum % n := by\n induction s using Multiset.induction <;> simp [Int.add_emod, *]\n#align multiset.sum_int_mod Multiset.sum_int_mod\n\ntheorem prod_int_mod (s : Multiset ℤ) (n : ℤ) : s.prod % n = (s.map (· % n)).prod % n := by\n induction s using Multiset.induction <;> ","nextTactic":"simp [Int.mul_emod, *]","declUpToTactic":"theorem prod_int_mod (s : Multiset ℤ) (n : ℤ) : s.prod % n = (s.map (· % n)).prod % n := by\n induction s using Multiset.induction <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.572_0.GN79r5lQgRvJg8p","decl":"theorem prod_int_mod (s : Multiset ℤ) (n : ℤ) : s.prod % n = (s.map (· % n)).prod % n "} +{"state":"case cons\nι : Type u_1\nα : Type u_2\nβ : Type u_3\nγ : Type u_4\nn a✝¹ : ℤ\ns✝ : Multiset ℤ\na✝ : prod s✝ % n = prod (map (fun x => x % n) s✝) % n\n⊢ prod (a✝¹ ::ₘ s✝) % n = prod (map (fun x => x % n) (a✝¹ ::ₘ s✝)) % n","srcUpToTactic":"/-\nCopyright (c) 2015 Microsoft Corporation. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport Mathlib.Data.List.BigOperators.Basic\nimport Mathlib.Data.Multiset.Basic\n\n#align_import algebra.big_operators.multiset.basic from \"leanprover-community/mathlib\"@\"6c5f73fd6f6cc83122788a80a27cdd54663609f4\"\n\n/-!\n# Sums and products over multisets\n\nIn this file we define products and sums indexed by multisets. This is later used to define products\nand sums indexed by finite sets.\n\n## Main declarations\n\n* `Multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with\n the cartesian product `Multiset.product`.\n* `Multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.\n\n## Implementation notes\n\nNov 2022: To speed the Lean 4 port, lemmas requiring extra algebra imports\n(`data.list.big_operators.lemmas` rather than `.basic`) have been moved to a separate file,\n`algebra.big_operators.multiset.lemmas`. This split does not need to be permanent.\n-/\n\n\nvariable {ι α β γ : Type*}\n\nnamespace Multiset\n\nsection CommMonoid\n\nvariable [CommMonoid α] {s t : Multiset α} {a : α} {m : Multiset ι} {f g : ι → α}\n\n/-- Product of a multiset given a commutative monoid structure on `α`.\n `prod {a, b, c} = a * b * c` -/\n@[to_additive\n \"Sum of a multiset given a commutative additive monoid structure on `α`.\n `sum {a, b, c} = a + b + c`\"]\ndef prod : Multiset α → α :=\n foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1\n#align multiset.prod Multiset.prod\n#align multiset.sum Multiset.sum\n\n@[to_additive]\ntheorem prod_eq_foldr (s : Multiset α) :\n prod s = foldr (· * ·) (fun x y z => by simp [mul_left_comm]) 1 s :=\n rfl\n#align multiset.prod_eq_foldr Multiset.prod_eq_foldr\n#align multiset.sum_eq_foldr Multiset.sum_eq_foldr\n\n@[to_additive]\ntheorem prod_eq_foldl (s : Multiset α) :\n prod s = foldl (· * ·) (fun x y z => by simp [mul_right_comm]) 1 s :=\n (foldr_swap _ _ _ _).trans (by simp [mul_comm])\n#align multiset.prod_eq_foldl Multiset.prod_eq_foldl\n#align multiset.sum_eq_foldl Multiset.sum_eq_foldl\n\n@[to_additive (attr := simp, norm_cast)]\ntheorem coe_prod (l : List α) : prod ↑l = l.prod :=\n prod_eq_foldl _\n#align multiset.coe_prod Multiset.coe_prod\n#align multiset.coe_sum Multiset.coe_sum\n\n@[to_additive (attr := simp)]\ntheorem prod_toList (s : Multiset α) : s.toList.prod = s.prod := by\n conv_rhs => rw [← coe_toList s]\n rw [coe_prod]\n#align multiset.prod_to_list Multiset.prod_toList\n#align multiset.sum_to_list Multiset.sum_toList\n\n@[to_additive (attr := simp)]\ntheorem prod_zero : @prod α _ 0 = 1 :=\n rfl\n#align multiset.prod_zero Multiset.prod_zero\n#align multiset.sum_zero Multiset.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s :=\n foldr_cons _ _ _ _ _\n#align multiset.prod_cons Multiset.prod_cons\n#align multiset.sum_cons Multiset.sum_cons\n\n@[to_additive (attr := simp)]\ntheorem prod_erase [DecidableEq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod := by\n rw [← s.coe_toList]\n rw [coe_erase]\n rw [coe_prod]\n rw [coe_prod]\n rw [List.prod_erase (mem_toList.2 h)]\n#align multiset.prod_erase Multiset.prod_erase\n#align multiset.sum_erase Multiset.sum_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_map_erase [DecidableEq ι] {a : ι} (h : a ∈ m) :\n f a * ((m.erase a).map f).prod = (m.map f).prod := by\n rw [← m.coe_toList, coe_erase, coe_map, coe_map, coe_prod, coe_prod,\n List.prod_map_erase f (mem_toList.2 h)]\n#align multiset.prod_map_erase Multiset.prod_map_erase\n#align multiset.sum_map_erase Multiset.sum_map_erase\n\n@[to_additive (attr := simp)]\ntheorem prod_singleton (a : α) : prod {a} = a := by\n simp only [mul_one, prod_cons, ← cons_zero, eq_self_iff_true, prod_zero]\n#align multiset.prod_singleton Multiset.prod_singleton\n#align multiset.sum_singleton Multiset.sum_singleton\n\n@[to_additive]\ntheorem prod_pair (a b : α) : ({a, b} : Multiset α).prod = a * b := by\n rw [insert_eq_cons]\n rw [prod_cons]\n rw [prod_singleton]\n#align multiset.prod_pair Multiset.prod_pair\n#align multiset.sum_pair Multiset.sum_pair\n\n@[to_additive (attr := simp)]\ntheorem prod_add (s t : Multiset α) : prod (s + t) = prod s * prod t :=\n Quotient.inductionOn₂ s t fun l₁ l₂ => by simp\n#align multiset.prod_add Multiset.prod_add\n#align multiset.sum_add Multiset.sum_add\n\n@[to_additive]\ntheorem prod_nsmul (m : Multiset α) : ∀ n : ℕ, (n • m).prod = m.prod ^ n\n | 0 => by\n rw [zero_nsmul]\n rw [pow_zero]\n rfl\n | n + 1 => by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul m n]\n#align multiset.prod_nsmul Multiset.prod_nsmul\n\n@[to_additive (attr := simp)]\ntheorem prod_replicate (n : ℕ) (a : α) : (replicate n a).prod = a ^ n := by\n simp [replicate, List.prod_replicate]\n#align multiset.prod_replicate Multiset.prod_replicate\n#align multiset.sum_replicate Multiset.sum_replicate\n\n@[to_additive]\ntheorem prod_map_eq_pow_single [DecidableEq ι] (i : ι)\n (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) : (m.map f).prod = f i ^ m.count i := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_map_eq_pow_single i f hf]\n#align multiset.prod_map_eq_pow_single Multiset.prod_map_eq_pow_single\n#align multiset.sum_map_eq_nsmul_single Multiset.sum_map_eq_nsmul_single\n\n@[to_additive]\ntheorem prod_eq_pow_single [DecidableEq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :\n s.prod = a ^ s.count a := by\n induction' s using Quotient.inductionOn with l\n simp [List.prod_eq_pow_single a h]\n#align multiset.prod_eq_pow_single Multiset.prod_eq_pow_single\n#align multiset.sum_eq_nsmul_single Multiset.sum_eq_nsmul_single\n\n@[to_additive]\ntheorem pow_count [DecidableEq α] (a : α) : a ^ s.count a = (s.filter (Eq a)).prod := by\n rw [filter_eq]\n rw [prod_replicate]\n#align multiset.pow_count Multiset.pow_count\n#align multiset.nsmul_count Multiset.nsmul_count\n\n@[to_additive]\ntheorem prod_hom [CommMonoid β] (s : Multiset α) {F : Type*} [MonoidHomClass F α β] (f : F) :\n (s.map f).prod = f s.prod :=\n Quotient.inductionOn s fun l => by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom Multiset.prod_hom\n#align multiset.sum_hom Multiset.sum_hom\n\n@[to_additive]\ntheorem prod_hom' [CommMonoid β] (s : Multiset ι) {F : Type*} [MonoidHomClass F α β] (f : F)\n (g : ι → α) : (s.map fun i => f <| g i).prod = f (s.map g).prod := by\n convert (s.map g).prod_hom f\n exact (map_map _ _ _).symm\n#align multiset.prod_hom' Multiset.prod_hom'\n#align multiset.sum_hom' Multiset.sum_hom'\n\n@[to_additive]\ntheorem prod_hom₂ [CommMonoid β] [CommMonoid γ] (s : Multiset ι) (f : α → β → γ)\n (hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α)\n (f₂ : ι → β) : (s.map fun i => f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom₂ Multiset.prod_hom₂\n#align multiset.sum_hom₂ Multiset.sum_hom₂\n\n@[to_additive]\ntheorem prod_hom_rel [CommMonoid β] (s : Multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}\n (h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n r (s.map f).prod (s.map g).prod :=\n Quotient.inductionOn s fun l => by\n simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]\n#align multiset.prod_hom_rel Multiset.prod_hom_rel\n#align multiset.sum_hom_rel Multiset.sum_hom_rel\n\n@[to_additive]\ntheorem prod_map_one : prod (m.map fun _ => (1 : α)) = 1 := by\n rw [map_const']\n rw [prod_replicate]\n rw [one_pow]\n#align multiset.prod_map_one Multiset.prod_map_one\n#align multiset.sum_map_zero Multiset.sum_map_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_map_mul : (m.map fun i => f i * g i).prod = (m.map f).prod * (m.map g).prod :=\n m.prod_hom₂ (· * ·) mul_mul_mul_comm (mul_one _) _ _\n#align multiset.prod_map_mul Multiset.prod_map_mul\n#align multiset.sum_map_add Multiset.sum_map_add\n\n@[simp]\ntheorem prod_map_neg [HasDistribNeg α] (s : Multiset α) :\n (s.map Neg.neg).prod = (-1) ^ card s * s.prod :=\n Quotient.inductionOn s (by simp)\n#align multiset.prod_map_neg Multiset.prod_map_neg\n\n@[to_additive]\ntheorem prod_map_pow {n : ℕ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n :=\n m.prod_hom' (powMonoidHom n : α →* α) f\n#align multiset.prod_map_pow Multiset.prod_map_pow\n#align multiset.sum_map_nsmul Multiset.sum_map_nsmul\n\n@[to_additive]\ntheorem prod_map_prod_map (m : Multiset β) (n : Multiset γ) {f : β → γ → α} :\n prod (m.map fun a => prod <| n.map fun b => f a b) =\n prod (n.map fun b => prod <| m.map fun a => f a b) :=\n Multiset.induction_on m (by simp) fun a m ih => by simp [ih]\n#align multiset.prod_map_prod_map Multiset.prod_map_prod_map\n#align multiset.sum_map_sum_map Multiset.sum_map_sum_map\n\n@[to_additive]\ntheorem prod_induction (p : α → Prop) (s : Multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))\n (p_one : p 1) (p_s : ∀ a ∈ s, p a) : p s.prod := by\n rw [prod_eq_foldr]\n exact foldr_induction (· * ·) (fun x y z => by simp [mul_left_comm]) 1 p s p_mul p_one p_s\n#align multiset.prod_induction Multiset.prod_induction\n#align multiset.sum_induction Multiset.sum_induction\n\n@[to_additive]\ntheorem prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b)) (hs : s ≠ ∅)\n (p_s : ∀ a ∈ s, p a) : p s.prod := by\n -- Porting note: used `refine' Multiset.induction _ _`\n induction' s using Multiset.induction_on with a s hsa\n · simp at hs\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty, p_s a]\n have hps : ∀ x, x ∈ s → p x := fun x hxs => p_s x (mem_cons_of_mem hxs)\n exact p_mul a s.prod (p_s a (mem_cons_self a s)) (hsa hs_empty hps)\n#align multiset.prod_induction_nonempty Multiset.prod_induction_nonempty\n#align multiset.sum_induction_nonempty Multiset.sum_induction_nonempty\n\ntheorem prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod := by\n obtain ⟨z, rfl⟩ := exists_add_of_le h\n simp only [prod_add, dvd_mul_right]\n#align multiset.prod_dvd_prod_of_le Multiset.prod_dvd_prod_of_le\n\nend CommMonoid\n\ntheorem prod_dvd_prod_of_dvd [CommMonoid β] {S : Multiset α} (g1 g2 : α → β)\n (h : ∀ a ∈ S, g1 a ∣ g2 a) : (Multiset.map g1 S).prod ∣ (Multiset.map g2 S).prod := by\n apply Multiset.induction_on' S\n · simp\n intro a T haS _ IH\n simp [mul_dvd_mul (h a haS) IH]\n#align multiset.prod_dvd_prod_of_dvd Multiset.prod_dvd_prod_of_dvd\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid α]\n\n/-- `Multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of\n`AddCommMonoid`s. -/\ndef sumAddMonoidHom : Multiset α →+ α where\n toFun := sum\n map_zero' := sum_zero\n map_add' := sum_add\n#align multiset.sum_add_monoid_hom Multiset.sumAddMonoidHom\n\n@[simp]\ntheorem coe_sumAddMonoidHom : (sumAddMonoidHom : Multiset α → α) = sum :=\n rfl\n#align multiset.coe_sum_add_monoid_hom Multiset.coe_sumAddMonoidHom\n\nend AddCommMonoid\n\nsection CommMonoidWithZero\n\nvariable [CommMonoidWithZero α]\n\ntheorem prod_eq_zero {s : Multiset α} (h : (0 : α) ∈ s) : s.prod = 0 := by\n rcases Multiset.exists_cons_of_mem h with ⟨s', hs'⟩\n simp [hs', Multiset.prod_cons]\n#align multiset.prod_eq_zero Multiset.prod_eq_zero\n\nvariable [NoZeroDivisors α] [Nontrivial α] {s : Multiset α}\n\ntheorem prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=\n Quotient.inductionOn s fun l => by\n rw [quot_mk_to_coe]\n rw [coe_prod]\n exact List.prod_eq_zero_iff\n#align multiset.prod_eq_zero_iff Multiset.prod_eq_zero_iff\n\ntheorem prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 :=\n mt prod_eq_zero_iff.1 h\n#align multiset.prod_ne_zero Multiset.prod_ne_zero\n\nend CommMonoidWithZero\n\nsection DivisionCommMonoid\n\nvariable [DivisionCommMonoid α] {m : Multiset ι} {f g : ι → α}\n\n@[to_additive]\ntheorem prod_map_inv' (m : Multiset α) : (m.map Inv.inv).prod = m.prod⁻¹ :=\n m.prod_hom (invMonoidHom : α →* α)\n#align multiset.prod_map_inv' Multiset.prod_map_inv'\n#align multiset.sum_map_neg' Multiset.sum_map_neg'\n\n@[to_additive (attr := simp)]\ntheorem prod_map_inv : (m.map fun i => (f i)⁻¹).prod = (m.map f).prod⁻¹ := by\n -- Porting note: used `convert`\n simp_rw [← (m.map f).prod_map_inv', map_map, Function.comp_apply]\n#align multiset.prod_map_inv Multiset.prod_map_inv\n#align multiset.sum_map_neg Multiset.sum_map_neg\n\n@[to_additive (attr := simp)]\ntheorem prod_map_div : (m.map fun i => f i / g i).prod = (m.map f).prod / (m.map g).prod :=\n m.prod_hom₂ (· / ·) mul_div_mul_comm (div_one _) _ _\n#align multiset.prod_map_div Multiset.prod_map_div\n#align multiset.sum_map_sub Multiset.sum_map_sub\n\n@[to_additive]\ntheorem prod_map_zpow {n : ℤ} : (m.map fun i => f i ^ n).prod = (m.map f).prod ^ n := by\n convert (m.map f).prod_hom (zpowGroupHom n : α →* α)\n simp only [map_map, Function.comp_apply, zpowGroupHom_apply]\n#align multiset.prod_map_zpow Multiset.prod_map_zpow\n#align multiset.sum_map_zsmul Multiset.sum_map_zsmul\n\nend DivisionCommMonoid\n\nsection NonUnitalNonAssocSemiring\n\nvariable [NonUnitalNonAssocSemiring α] {a : α} {s : Multiset ι} {f : ι → α}\n\ntheorem sum_map_mul_left : sum (s.map fun i => a * f i) = a * sum (s.map f) :=\n Multiset.induction_on s (by simp) fun i s ih => by simp [ih, mul_add]\n#align multiset.sum_map_mul_left Multiset.sum_map_mul_left\n\ntheorem sum_map_mul_right : sum (s.map fun i => f i * a) = sum (s.map f) * a :=\n Multiset.induction_on s (by simp) fun a s ih => by simp [ih, add_mul]\n#align multiset.sum_map_mul_right Multiset.sum_map_mul_right\n\nend NonUnitalNonAssocSemiring\n\nsection NonUnitalSemiring\n\nvariable [NonUnitalSemiring α]\n\ntheorem dvd_sum {a : α} {s : Multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=\n Multiset.induction_on s (fun _ => dvd_zero _) fun x s ih h => by\n rw [sum_cons]\n exact dvd_add (h _ (mem_cons_self _ _)) (ih fun y hy => h _ <| mem_cons.2 <| Or.inr hy)\n#align multiset.dvd_sum Multiset.dvd_sum\n\nend NonUnitalSemiring\n\n/-! ### Order -/\n\n\nsection OrderedCommMonoid\n\nvariable [OrderedCommMonoid α] {s t : Multiset α} {a : α}\n\n@[to_additive sum_nonneg]\ntheorem one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=\n Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl\n#align multiset.one_le_prod_of_one_le Multiset.one_le_prod_of_one_le\n#align multiset.sum_nonneg Multiset.sum_nonneg\n\n@[to_additive]\ntheorem single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=\n Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx\n#align multiset.single_le_prod Multiset.single_le_prod\n#align multiset.single_le_sum Multiset.single_le_sum\n\n@[to_additive sum_le_card_nsmul]\ntheorem prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by\n induction s using Quotient.inductionOn\n simpa using List.prod_le_pow_card _ _ h\n#align multiset.prod_le_pow_card Multiset.prod_le_pow_card\n#align multiset.sum_le_card_nsmul Multiset.sum_le_card_nsmul\n\n@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]\ntheorem all_one_of_le_one_le_of_prod_eq_one :\n (∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=\n Quotient.inductionOn s (by\n simp only [quot_mk_to_coe, coe_prod, mem_coe]\n exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)\n#align multiset.all_one_of_le_one_le_of_prod_eq_one Multiset.all_one_of_le_one_le_of_prod_eq_one\n#align multiset.all_zero_of_le_zero_le_of_sum_eq_zero Multiset.all_zero_of_le_zero_le_of_sum_eq_zero\n\n@[to_additive]\ntheorem prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by\n induction' h with _ _ _ _ rh _ rt\n · rfl\n · rw [prod_cons, prod_cons]\n exact mul_le_mul' rh rt\n#align multiset.prod_le_prod_of_rel_le Multiset.prod_le_prod_of_rel_le\n#align multiset.sum_le_sum_of_rel_le Multiset.sum_le_sum_of_rel_le\n\n@[to_additive]\ntheorem prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :\n (s.map f).prod ≤ (s.map g).prod :=\n prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod_map Multiset.prod_map_le_prod_map\n#align multiset.sum_map_le_sum_map Multiset.sum_map_le_sum_map\n\n@[to_additive]\ntheorem prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=\n prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h\n#align multiset.prod_map_le_prod Multiset.prod_map_le_prod\n#align multiset.sum_map_le_sum Multiset.sum_map_le_sum\n\n@[to_additive]\ntheorem prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=\n @prod_map_le_prod αᵒᵈ _ _ f h\n#align multiset.prod_le_prod_map Multiset.prod_le_prod_map\n#align multiset.sum_le_sum_map Multiset.sum_le_sum_map\n\n@[to_additive card_nsmul_le_sum]\ntheorem pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by\n rw [← Multiset.prod_replicate]\n rw [← Multiset.map_const]\n exact prod_map_le_prod _ h\n#align multiset.pow_card_le_prod Multiset.pow_card_le_prod\n#align multiset.card_nsmul_le_sum Multiset.card_nsmul_le_sum\n\nend OrderedCommMonoid\n\nsection OrderedCancelCommMonoid\n\nvariable [OrderedCancelCommMonoid α] {s : Multiset ι} {f g : ι → α}\n\n@[to_additive sum_lt_sum]\ntheorem prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨l⟩ := s\n simp only [Multiset.quot_mk_to_coe'', Multiset.coe_map, Multiset.coe_prod]\n exact List.prod_lt_prod' f g hle hlt\n\n@[to_additive sum_lt_sum_of_nonempty]\ntheorem prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :\n (s.map f).prod < (s.map g).prod := by\n obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs\n exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩\n\nend OrderedCancelCommMonoid\n\ntheorem prod_nonneg [OrderedCommSemiring α] {m : Multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :\n 0 ≤ m.prod := by\n revert h\n refine' m.induction_on _ _\n · rintro -\n rw [prod_zero]\n exact zero_le_one\n intro a s hs ih\n rw [prod_cons]\n exact mul_nonneg (ih _ <| mem_cons_self _ _) (hs fun a ha => ih _ <| mem_cons_of_mem ha)\n#align multiset.prod_nonneg Multiset.prod_nonneg\n\n/-- Slightly more general version of `Multiset.prod_eq_one_iff` for a non-ordered `Monoid` -/\n@[to_additive\n \"Slightly more general version of `Multiset.sum_eq_zero_iff` for a non-ordered `AddMonoid`\"]\ntheorem prod_eq_one [CommMonoid α] {m : Multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 := by\n induction' m using Quotient.inductionOn with l\n simp [List.prod_eq_one h]\n#align multiset.prod_eq_one Multiset.prod_eq_one\n#align multiset.sum_eq_zero Multiset.sum_eq_zero\n\n@[to_additive]\ntheorem le_prod_of_mem [CanonicallyOrderedCommMonoid α] {m : Multiset α} {a : α} (h : a ∈ m) :\n a ≤ m.prod := by\n obtain ⟨m', rfl⟩ := exists_cons_of_mem h\n rw [prod_cons]\n exact _root_.le_mul_right (le_refl a)\n#align multiset.le_prod_of_mem Multiset.le_prod_of_mem\n#align multiset.le_sum_of_mem Multiset.le_sum_of_mem\n\n@[to_additive le_sum_of_subadditive_on_pred]\ntheorem le_prod_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)\n (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))\n (s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · simp [le_of_eq h_one]\n intro a s hs hpsa\n have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)\n have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)\n#align multiset.le_prod_of_submultiplicative_on_pred Multiset.le_prod_of_submultiplicative_on_pred\n#align multiset.le_sum_of_subadditive_on_pred Multiset.le_sum_of_subadditive_on_pred\n\n@[to_additive le_sum_of_subadditive]\ntheorem le_prod_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)\n (by simp) s (by simp)\n#align multiset.le_prod_of_submultiplicative Multiset.le_prod_of_submultiplicative\n#align multiset.le_sum_of_subadditive Multiset.le_sum_of_subadditive\n\n@[to_additive le_sum_nonempty_of_subadditive_on_pred]\ntheorem le_prod_nonempty_of_submultiplicative_on_pred [CommMonoid α] [OrderedCommMonoid β]\n (f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)\n (hp_mul : ∀ a b, p a → p b → p (a * b)) (s : Multiset α) (hs_nonempty : s ≠ ∅)\n (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by\n revert s\n refine' Multiset.induction _ _\n · intro h\n exfalso\n exact h rfl\n rintro a s hs - hsa_prop\n rw [prod_cons]\n rw [map_cons]\n rw [prod_cons]\n by_cases hs_empty : s = ∅\n · simp [hs_empty]\n have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)\n have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict\n have hp_a : p a := hsa_prop a (mem_cons_self a s)\n exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)\n#align multiset.le_prod_nonempty_of_submultiplicative_on_pred Multiset.le_prod_nonempty_of_submultiplicative_on_pred\n#align multiset.le_sum_nonempty_of_subadditive_on_pred Multiset.le_sum_nonempty_of_subadditive_on_pred\n\n@[to_additive le_sum_nonempty_of_subadditive]\ntheorem le_prod_nonempty_of_submultiplicative [CommMonoid α] [OrderedCommMonoid β] (f : α → β)\n (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) (hs_nonempty : s ≠ ∅) :\n f s.prod ≤ (s.map f).prod :=\n le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by simp [h_mul]) (by simp) s\n hs_nonempty (by simp)\n#align multiset.le_prod_nonempty_of_submultiplicative Multiset.le_prod_nonempty_of_submultiplicative\n#align multiset.le_sum_nonempty_of_subadditive Multiset.le_sum_nonempty_of_subadditive\n\n@[simp]\ntheorem sum_map_singleton (s : Multiset α) : (s.map fun a => ({a} : Multiset α)).sum = s :=\n Multiset.induction_on s (by simp) (by simp)\n#align multiset.sum_map_singleton Multiset.sum_map_singleton\n\ntheorem abs_sum_le_sum_abs [LinearOrderedAddCommGroup α] {s : Multiset α} :\n abs s.sum ≤ (s.map abs).sum :=\n le_sum_of_subadditive _ abs_zero abs_add s\n#align multiset.abs_sum_le_sum_abs Multiset.abs_sum_le_sum_abs\n\ntheorem sum_nat_mod (s : Multiset ℕ) (n : ℕ) : s.sum % n = (s.map (· % n)).sum % n := by\n induction s using Multiset.induction <;> simp [Nat.add_mod, *]\n#align multiset.sum_nat_mod Multiset.sum_nat_mod\n\ntheorem prod_nat_mod (s : Multiset ℕ) (n : ℕ) : s.prod % n = (s.map (· % n)).prod % n := by\n induction s using Multiset.induction <;> simp [Nat.mul_mod, *]\n#align multiset.prod_nat_mod Multiset.prod_nat_mod\n\ntheorem sum_int_mod (s : Multiset ℤ) (n : ℤ) : s.sum % n = (s.map (· % n)).sum % n := by\n induction s using Multiset.induction <;> simp [Int.add_emod, *]\n#align multiset.sum_int_mod Multiset.sum_int_mod\n\ntheorem prod_int_mod (s : Multiset ℤ) (n : ℤ) : s.prod % n = (s.map (· % n)).prod % n := by\n induction s using Multiset.induction <;> ","nextTactic":"simp [Int.mul_emod, *]","declUpToTactic":"theorem prod_int_mod (s : Multiset ℤ) (n : ℤ) : s.prod % n = (s.map (· % n)).prod % n := by\n induction s using Multiset.induction <;> ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Multiset_Basic.572_0.GN79r5lQgRvJg8p","decl":"theorem prod_int_mod (s : Multiset ℤ) (n : ℤ) : s.prod % n = (s.map (· % n)).prod % n "}