diff --git "a/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_BigOperators_Finsupp.jsonl" "b/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_BigOperators_Finsupp.jsonl" deleted file mode 100644--- "a/Extracted/Mathlib/TacticPrediction/Mathlib_Algebra_BigOperators_Finsupp.jsonl" +++ /dev/null @@ -1,136 +0,0 @@ -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : Zero M\ninst✝¹ : Zero M'\ninst✝ : CommMonoid N\nf : α →₀ M\ns : Finset α\nhs : f.support ⊆ s\ng : α → M → N\nh : ∀ i ∈ s, g i 0 = 1\n⊢ prod f g = ∏ x in s, g x (f x)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n ","nextTactic":"refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)","declUpToTactic":"@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.59_0.MEVUz78Vsm81fPx","decl":"@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx✝ : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : Zero M\ninst✝¹ : Zero M'\ninst✝ : CommMonoid N\nf : α →₀ M\ns : Finset α\nhs : f.support ⊆ s\ng : α → M → N\nh : ∀ i ∈ s, g i 0 = 1\nx : α\nhxs : x ∈ s\nhx : x ∉ f.support\n⊢ f x = 0","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n ","nextTactic":"exact not_mem_support_iff.1 hx","declUpToTactic":"@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.59_0.MEVUz78Vsm81fPx","decl":"@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : Zero M\ninst✝¹ : Zero M'\ninst✝ : CommMonoid N\na : α\nb : M\nh : α → M → N\nh_zero : h a 0 = 1\n⊢ ∏ x in {a}, h x ((single a b) x) = h a b","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by ","nextTactic":"simp","declUpToTactic":"@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.74_0.MEVUz78Vsm81fPx","decl":"@[to_additive (attr "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0✝ : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH✝ : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : Zero M\ninst✝¹ : Zero M'\ninst✝ : CommMonoid N\nf : M → M'\nhf : f 0 = 0\ng : α →₀ M\nh : α → M' → N\nh0 : ∀ (a : α), h a 0 = 1\nx✝¹ : α\nx✝ : x✝¹ ∈ g.support\nH : x✝¹ ∉ (mapRange f hf g).support\n⊢ h x✝¹ ((mapRange f hf g) x✝¹) = 1","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by ","nextTactic":"rw [not_mem_support_iff.1 H, h0]","declUpToTactic":"@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.85_0.MEVUz78Vsm81fPx","decl":"@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁶ : AddCommMonoid A\ninst✝⁵ : AddCommMonoid B\ninst✝⁴ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝³ : Zero M\ninst✝² : Zero M'\ninst✝¹ : CommMonoid N\ninst✝ : DecidableEq α\nf : α →₀ M\na : α\nb : α → M → N\n⊢ (prod f fun x v => if a = x then b x v else 1) = if a ∈ f.support then b a (f a) else 1","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n ","nextTactic":"dsimp [Finsupp.prod]","declUpToTactic":"@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.106_0.MEVUz78Vsm81fPx","decl":"@[to_additive (attr "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁶ : AddCommMonoid A\ninst✝⁵ : AddCommMonoid B\ninst✝⁴ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝³ : Zero M\ninst✝² : Zero M'\ninst✝¹ : CommMonoid N\ninst✝ : DecidableEq α\nf : α →₀ M\na : α\nb : α → M → N\n⊢ (∏ a_1 in f.support, if a = a_1 then b a_1 (f a_1) else 1) = if a ∈ f.support then b a (f a) else 1","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n ","nextTactic":"rw [f.support.prod_ite_eq]","declUpToTactic":"@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.106_0.MEVUz78Vsm81fPx","decl":"@[to_additive (attr "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁷ : AddCommMonoid A\ninst✝⁶ : AddCommMonoid B\ninst✝⁵ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN✝ : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝⁴ : Zero M\ninst✝³ : Zero M'\ninst✝² : CommMonoid N✝\ninst✝¹ : DecidableEq α\nN : Type u_16\ninst✝ : AddCommMonoid N\nf : α →₀ N\na : α\n⊢ (sum f fun x v => if a = x then v else 0) = f a","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n ","nextTactic":"classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]","declUpToTactic":"theorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.121_0.MEVUz78Vsm81fPx","decl":"theorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁷ : AddCommMonoid A\ninst✝⁶ : AddCommMonoid B\ninst✝⁵ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN✝ : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝⁴ : Zero M\ninst✝³ : Zero M'\ninst✝² : CommMonoid N✝\ninst✝¹ : DecidableEq α\nN : Type u_16\ninst✝ : AddCommMonoid N\nf : α →₀ N\na : α\n⊢ (sum f fun x v => if a = x then v else 0) = f a","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n ","nextTactic":"convert f.sum_ite_eq a fun _ => id","declUpToTactic":"theorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.121_0.MEVUz78Vsm81fPx","decl":"theorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a "} -{"state":"case h.e'_3\nα : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁷ : AddCommMonoid A\ninst✝⁶ : AddCommMonoid B\ninst✝⁵ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN✝ : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝⁴ : Zero M\ninst✝³ : Zero M'\ninst✝² : CommMonoid N✝\ninst✝¹ : DecidableEq α\nN : Type u_16\ninst✝ : AddCommMonoid N\nf : α →₀ N\na : α\n⊢ f a = if a ∈ f.support then id (f a) else 0","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n ","nextTactic":"simp [ite_eq_right_iff.2 Eq.symm]","declUpToTactic":"theorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.121_0.MEVUz78Vsm81fPx","decl":"theorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁷ : AddCommMonoid A\ninst✝⁶ : AddCommMonoid B\ninst✝⁵ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN✝ : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝⁴ : Zero M\ninst✝³ : Zero M'\ninst✝² : CommMonoid N✝\ninst✝¹ : DecidableEq α\nN : Type u_16\ninst✝ : AddCommMonoid N\nf : α →₀ N\na : α\n⊢ (if a ∈ f.support then f a else 0) = f a","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n ","nextTactic":"simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]","declUpToTactic":"@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.129_0.MEVUz78Vsm81fPx","decl":"@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁷ : AddCommMonoid A\ninst✝⁶ : AddCommMonoid B\ninst✝⁵ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN✝ : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝⁴ : Zero M\ninst✝³ : Zero M'\ninst✝² : CommMonoid N✝\ninst✝¹ : DecidableEq α\nN : Type u_16\ninst✝ : AddCommMonoid N\nf : α →₀ N\na : α\n⊢ f a = 0 → 0 = f a","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n ","nextTactic":"exact fun h ↦ h.symm","declUpToTactic":"@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.129_0.MEVUz78Vsm81fPx","decl":"@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁶ : AddCommMonoid A\ninst✝⁵ : AddCommMonoid B\ninst✝⁴ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝³ : Zero M\ninst✝² : Zero M'\ninst✝¹ : CommMonoid N\ninst✝ : DecidableEq α\nf : α →₀ M\na : α\nb : α → M → N\n⊢ (prod f fun x v => if x = a then b x v else 1) = if a ∈ f.support then b a (f a) else 1","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n ","nextTactic":"dsimp [Finsupp.prod]","declUpToTactic":"/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.135_0.MEVUz78Vsm81fPx","decl":"/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁶ : AddCommMonoid A\ninst✝⁵ : AddCommMonoid B\ninst✝⁴ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝³ : Zero M\ninst✝² : Zero M'\ninst✝¹ : CommMonoid N\ninst✝ : DecidableEq α\nf : α →₀ M\na : α\nb : α → M → N\n⊢ (∏ a_1 in f.support, if a_1 = a then b a_1 (f a_1) else 1) = if a ∈ f.support then b a (f a) else 1","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n ","nextTactic":"rw [f.support.prod_ite_eq']","declUpToTactic":"/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.135_0.MEVUz78Vsm81fPx","decl":"/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁷ : AddCommMonoid A\ninst✝⁶ : AddCommMonoid B\ninst✝⁵ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN✝ : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝⁴ : Zero M\ninst✝³ : Zero M'\ninst✝² : CommMonoid N✝\ninst✝¹ : DecidableEq α\nN : Type u_16\ninst✝ : AddCommMonoid N\nf : α →₀ N\na : α\n⊢ (sum f fun x v => if x = a then v else 0) = f a","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n ","nextTactic":"classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]","declUpToTactic":"theorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.146_0.MEVUz78Vsm81fPx","decl":"theorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁷ : AddCommMonoid A\ninst✝⁶ : AddCommMonoid B\ninst✝⁵ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN✝ : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝⁴ : Zero M\ninst✝³ : Zero M'\ninst✝² : CommMonoid N✝\ninst✝¹ : DecidableEq α\nN : Type u_16\ninst✝ : AddCommMonoid N\nf : α →₀ N\na : α\n⊢ (sum f fun x v => if x = a then v else 0) = f a","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n ","nextTactic":"convert f.sum_ite_eq' a fun _ => id","declUpToTactic":"theorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.146_0.MEVUz78Vsm81fPx","decl":"theorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a "} -{"state":"case h.e'_3\nα : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁷ : AddCommMonoid A\ninst✝⁶ : AddCommMonoid B\ninst✝⁵ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN✝ : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝⁴ : Zero M\ninst✝³ : Zero M'\ninst✝² : CommMonoid N✝\ninst✝¹ : DecidableEq α\nN : Type u_16\ninst✝ : AddCommMonoid N\nf : α →₀ N\na : α\n⊢ f a = if a ∈ f.support then id (f a) else 0","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n ","nextTactic":"simp [ite_eq_right_iff.2 Eq.symm]","declUpToTactic":"theorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.146_0.MEVUz78Vsm81fPx","decl":"theorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : Zero M\ninst✝¹ : Zero M'\ninst✝ : CommMonoid N\ns : Finset α\nf : α → M\ng : α → M → N\nhf : ∀ (a : α), f a ≠ 0 → a ∈ s\nhg : ∀ (a : α), g a 0 = 1\n⊢ ∀ x ∈ s, x ∉ (onFinset s f hf).support → g x ((onFinset s f hf) x) = 1","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by ","nextTactic":"simp (config := { contextual := true }) [*]","declUpToTactic":"/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.159_0.MEVUz78Vsm81fPx","decl":"/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : Zero M\ninst✝¹ : Zero M'\ninst✝ : CommMonoid N\nf : α →₀ M\ny : α\ng : α → M → N\nhyf : y ∈ f.support\n⊢ g y (f y) * prod (erase y f) g = prod f g","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n ","nextTactic":"classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]","declUpToTactic":"/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.170_0.MEVUz78Vsm81fPx","decl":"/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : Zero M\ninst✝¹ : Zero M'\ninst✝ : CommMonoid N\nf : α →₀ M\ny : α\ng : α → M → N\nhyf : y ∈ f.support\n⊢ g y (f y) * prod (erase y f) g = prod f g","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n ","nextTactic":"rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]","declUpToTactic":"/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.170_0.MEVUz78Vsm81fPx","decl":"/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : Zero M\ninst✝¹ : Zero M'\ninst✝ : CommMonoid N\nf : α →₀ M\ny : α\ng : α → M → N\nhyf : y ∈ f.support\n⊢ ∀ x ∈ Finset.erase f.support y, g x ((erase y f) x) = g x (f x)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n ","nextTactic":"intro h hx","declUpToTactic":"/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.170_0.MEVUz78Vsm81fPx","decl":"/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : Zero M\ninst✝¹ : Zero M'\ninst✝ : CommMonoid N\nf : α →₀ M\ny : α\ng : α → M → N\nhyf : y ∈ f.support\nh : α\nhx : h ∈ Finset.erase f.support y\n⊢ g h ((erase y f) h) = g h (f h)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n ","nextTactic":"rw [Finsupp.erase_ne (ne_of_mem_erase hx)]","declUpToTactic":"/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.170_0.MEVUz78Vsm81fPx","decl":"/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : Zero M\ninst✝¹ : Zero M'\ninst✝ : CommMonoid N\nf : α →₀ M\ny : α\ng : α → M → N\nhg : ∀ (i : α), g i 0 = 1\n⊢ g y (f y) * prod (erase y f) g = prod f g","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n ","nextTactic":"classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]","declUpToTactic":"/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.185_0.MEVUz78Vsm81fPx","decl":"/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : Zero M\ninst✝¹ : Zero M'\ninst✝ : CommMonoid N\nf : α →₀ M\ny : α\ng : α → M → N\nhg : ∀ (i : α), g i 0 = 1\n⊢ g y (f y) * prod (erase y f) g = prod f g","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n ","nextTactic":"by_cases hyf : y ∈ f.support","declUpToTactic":"/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.185_0.MEVUz78Vsm81fPx","decl":"/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g "} -{"state":"case pos\nα : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : Zero M\ninst✝¹ : Zero M'\ninst✝ : CommMonoid N\nf : α →₀ M\ny : α\ng : α → M → N\nhg : ∀ (i : α), g i 0 = 1\nhyf : y ∈ f.support\n⊢ g y (f y) * prod (erase y f) g = prod f g","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · ","nextTactic":"exact Finsupp.mul_prod_erase f y g hyf","declUpToTactic":"/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.185_0.MEVUz78Vsm81fPx","decl":"/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g "} -{"state":"case neg\nα : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : Zero M\ninst✝¹ : Zero M'\ninst✝ : CommMonoid N\nf : α →₀ M\ny : α\ng : α → M → N\nhg : ∀ (i : α), g i 0 = 1\nhyf : y ∉ f.support\n⊢ g y (f y) * prod (erase y f) g = prod f g","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · ","nextTactic":"rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]","declUpToTactic":"/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.185_0.MEVUz78Vsm81fPx","decl":"/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : Zero M\ninst✝¹ : Zero M'\ninst✝ : CommMonoid N\nf : α →₀ M\na : α\ng : α → M → N\nh₀ : ∀ (b : α), f b ≠ 0 → b ≠ a → g b (f b) = 1\nh₁ : f a = 0 → g a 0 = 1\n⊢ prod f g = g a (f a)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n ","nextTactic":"refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)","declUpToTactic":"@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.215_0.MEVUz78Vsm81fPx","decl":"@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) "} -{"state":"case refine_1\nα : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : Zero M\ninst✝¹ : Zero M'\ninst✝ : CommMonoid N\nf : α →₀ M\na : α\ng : α → M → N\nh₀ : ∀ (b : α), f b ≠ 0 → b ≠ a → g b (f b) = 1\nh₁ : f a = 0 → g a 0 = 1\nb : α\nhb₁ : b ∈ f.support\nhb₂ : b ≠ a\n⊢ g b (f b) = 1","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · ","nextTactic":"exact h₀ b (mem_support_iff.mp hb₁) hb₂","declUpToTactic":"@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.215_0.MEVUz78Vsm81fPx","decl":"@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) "} -{"state":"case refine_2\nα : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : Zero M\ninst✝¹ : Zero M'\ninst✝ : CommMonoid N\nf : α →₀ M\na : α\ng : α → M → N\nh₀ : ∀ (b : α), f b ≠ 0 → b ≠ a → g b (f b) = 1\nh₁ : f a = 0 → g a 0 = 1\nh : a ∉ f.support\n⊢ g a (f a) = 1","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · ","nextTactic":"simp only [not_mem_support_iff] at h","declUpToTactic":"@[to_additive]\ntheorem prod_eq_single {f : �� →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.215_0.MEVUz78Vsm81fPx","decl":"@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) "} -{"state":"case refine_2\nα : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : Zero M\ninst✝¹ : Zero M'\ninst✝ : CommMonoid N\nf : α →₀ M\na : α\ng : α → M → N\nh₀ : ∀ (b : α), f b ≠ 0 → b ≠ a → g b (f b) = 1\nh₁ : f a = 0 → g a 0 = 1\nh : f a = 0\n⊢ g a (f a) = 1","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α ��� M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n ","nextTactic":"rw [h]","declUpToTactic":"@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.215_0.MEVUz78Vsm81fPx","decl":"@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) "} -{"state":"case refine_2\nα : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : Zero M\ninst✝¹ : Zero M'\ninst✝ : CommMonoid N\nf : α →₀ M\na : α\ng : α → M → N\nh₀ : ∀ (b : α), f b ≠ 0 → b ≠ a → g b (f b) = 1\nh₁ : f a = 0 → g a 0 = 1\nh : f a = 0\n⊢ g a 0 = 1","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n ","nextTactic":"exact h₁ h","declUpToTactic":"@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.215_0.MEVUz78Vsm81fPx","decl":"@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝¹ : Finset α\nf : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\ns✝ : Multiset M\na✝ : α\na : M\ns : Multiset M\nih : single a✝ (Multiset.sum s) = Multiset.sum (Multiset.map (single a✝) s)\n⊢ single a✝ (Multiset.sum (a ::ₘ s)) = Multiset.sum (Multiset.map (single a✝) (a ::ₘ s))","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n ","nextTactic":"rw [Multiset.sum_cons]","declUpToTactic":"theorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.294_0.MEVUz78Vsm81fPx","decl":"theorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝¹ : Finset α\nf : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\ns✝ : Multiset M\na✝ : α\na : M\ns : Multiset M\nih : single a✝ (Multiset.sum s) = Multiset.sum (Multiset.map (single a✝) s)\n⊢ single a✝ (a + Multiset.sum s) = Multiset.sum (Multiset.map (single a✝) (a ::ₘ s))","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n ","nextTactic":"rw [single_add]","declUpToTactic":"theorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.294_0.MEVUz78Vsm81fPx","decl":"theorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝¹ : Finset α\nf : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\ns✝ : Multiset M\na✝ : α\na : M\ns : Multiset M\nih : single a✝ (Multiset.sum s) = Multiset.sum (Multiset.map (single a✝) s)\n⊢ single a✝ a + single a✝ (Multiset.sum s) = Multiset.sum (Multiset.map (single a✝) (a ::ₘ s))","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n ","nextTactic":"rw [ih]","declUpToTactic":"theorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.294_0.MEVUz78Vsm81fPx","decl":"theorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝¹ : Finset α\nf : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\ns✝ : Multiset M\na✝ : α\na : M\ns : Multiset M\nih : single a✝ (Multiset.sum s) = Multiset.sum (Multiset.map (single a✝) s)\n⊢ single a✝ a + Multiset.sum (Multiset.map (single a✝) s) = Multiset.sum (Multiset.map (single a✝) (a ::ₘ s))","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β ��� M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n ","nextTactic":"rw [Multiset.map_cons]","declUpToTactic":"theorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.294_0.MEVUz78Vsm81fPx","decl":"theorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝¹ : Finset α\nf : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\ns✝ : Multiset M\na✝ : α\na : M\ns : Multiset M\nih : single a✝ (Multiset.sum s) = Multiset.sum (Multiset.map (single a✝) s)\n⊢ single a✝ a + Multiset.sum (Multiset.map (single a✝) s) = Multiset.sum (single a✝ a ::ₘ Multiset.map (single a✝) s)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n ","nextTactic":"rw [Multiset.sum_cons]","declUpToTactic":"theorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.294_0.MEVUz78Vsm81fPx","decl":"theorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\ns : Finset ι\nf : ι → M\na : α\n⊢ single a (∑ b in s, f b) = ∑ b in s, single a (f b)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n ","nextTactic":"trans","declUpToTactic":"theorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.304_0.MEVUz78Vsm81fPx","decl":"theorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\ns : Finset ι\nf : ι → M\na : α\n⊢ single a (∑ b in s, f b) = ?m.266147","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · ","nextTactic":"apply single_multiset_sum","declUpToTactic":"theorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.304_0.MEVUz78Vsm81fPx","decl":"theorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\ns : Finset ι\nf : ι → M\na : α\n⊢ Multiset.sum (Multiset.map (single a) (Multiset.map (fun b => f b) s.val)) = ∑ b in s, single a (f b)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : �� → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · ","nextTactic":"rw [Multiset.map_map]","declUpToTactic":"theorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.304_0.MEVUz78Vsm81fPx","decl":"theorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\ns : Finset ι\nf : ι → M\na : α\n⊢ Multiset.sum (Multiset.map (single a ∘ fun b => f b) s.val) = ∑ b in s, single a (f b)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n ","nextTactic":"rfl","declUpToTactic":"theorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.304_0.MEVUz78Vsm81fPx","decl":"theorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : DecidableEq β\ninst✝¹ : Zero M\ninst✝ : AddCommMonoid N\nf : α →₀ M\ng : α → M → β →₀ N\n⊢ (sum f g).support ⊆ Finset.biUnion f.support fun a => (g a (f a)).support","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n ","nextTactic":"have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩","declUpToTactic":"theorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.351_0.MEVUz78Vsm81fPx","decl":"theorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : DecidableEq β\ninst✝¹ : Zero M\ninst✝ : AddCommMonoid N\nf : α →₀ M\ng : α → M → β →₀ N\nthis : ∀ (c : β), (sum f fun a b => (g a b) c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0\n⊢ (sum f g).support ⊆ Finset.biUnion f.support fun a => (g a (f a)).support","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n ","nextTactic":"simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]","declUpToTactic":"theorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.351_0.MEVUz78Vsm81fPx","decl":"theorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : DecidableEq β\ninst✝ : AddCommMonoid M\ns : Finset α\nf : α → β →₀ M\n⊢ (Finset.sum s f).support ⊆ Finset.biUnion s fun x => (f x).support","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n ","nextTactic":"rw [← Finset.sup_eq_biUnion]","declUpToTactic":"theorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.359_0.MEVUz78Vsm81fPx","decl":"theorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : DecidableEq β\ninst✝ : AddCommMonoid M\ns : Finset α\nf : α → β →₀ M\n⊢ (Finset.sum s f).support ⊆ sup s fun x => (f x).support","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n ","nextTactic":"induction' s using Finset.cons_induction_on with a s ha ih","declUpToTactic":"theorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.359_0.MEVUz78Vsm81fPx","decl":"theorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support "} -{"state":"case h₁\nα : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : DecidableEq β\ninst✝ : AddCommMonoid M\nf : α → β →₀ M\n⊢ (Finset.sum ∅ f).support ⊆ sup ∅ fun x => (f x).support","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · ","nextTactic":"rfl","declUpToTactic":"theorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.359_0.MEVUz78Vsm81fPx","decl":"theorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support "} -{"state":"case h₂\nα : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : DecidableEq β\ninst✝ : AddCommMonoid M\nf : α → β →₀ M\na : α\ns : Finset α\nha : a ∉ s\nih : (Finset.sum s f).support ⊆ sup s fun x => (f x).support\n⊢ (Finset.sum (Finset.cons a s ha) f).support ⊆ sup (Finset.cons a s ha) fun x => (f x).support","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · ","nextTactic":"rw [Finset.sum_cons, Finset.sup_cons]","declUpToTactic":"theorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.359_0.MEVUz78Vsm81fPx","decl":"theorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support "} -{"state":"case h₂\nα : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : DecidableEq β\ninst✝ : AddCommMonoid M\nf : α → β →₀ M\na : α\ns : Finset α\nha : a ∉ s\nih : (Finset.sum s f).support ⊆ sup s fun x => (f x).support\n⊢ (f a + ∑ x in s, f x).support ⊆ (f a).support ⊔ sup s fun x => (f x).support","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n ","nextTactic":"exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)","declUpToTactic":"theorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.359_0.MEVUz78Vsm81fPx","decl":"theorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : DecidableEq α\ninst✝¹ : AddZeroClass M\ninst✝ : CommMonoid N\nf g : α →₀ M\nh : α → M → N\nh_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1\nh_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ * h a b₂\n⊢ prod (f + g) h = prod f h * prod g h","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n ","nextTactic":"rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]","declUpToTactic":"/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.393_0.MEVUz78Vsm81fPx","decl":"/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : DecidableEq α\ninst✝¹ : AddZeroClass M\ninst✝ : CommMonoid N\nf g : α →₀ M\nh : α → M → N\nh_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1\nh_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ * h a b₂\n⊢ ∏ x in f.support ∪ g.support, h x ((f + g) x) = ∏ x in f.support ∪ g.support, h x (f x) * h x (g x)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n ","nextTactic":"exact Finset.prod_congr rfl fun x hx => by apply h_add x hx","declUpToTactic":"/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.393_0.MEVUz78Vsm81fPx","decl":"/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx✝ : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : DecidableEq α\ninst✝¹ : AddZeroClass M\ninst✝ : CommMonoid N\nf g : α →₀ M\nh : α → M → N\nh_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1\nh_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ * h a b₂\nx : α\nhx : x ∈ f.support ∪ g.support\n⊢ h x ((f + g) x) = h x (f x) * h x (g x)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by ","nextTactic":"apply h_add x hx","declUpToTactic":"/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.393_0.MEVUz78Vsm81fPx","decl":"/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddZeroClass M\ninst✝ : CommMonoid N\nf g : α →₀ M\nh : α → M → N\nh_zero : ∀ (a : α), h a 0 = 1\nh_add : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ * h a b₂\n⊢ prod (f + g) h = prod f h * prod g h","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n ","nextTactic":"classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a","declUpToTactic":"/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.411_0.MEVUz78Vsm81fPx","decl":"/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddZeroClass M\ninst✝ : CommMonoid N\nf g : α →₀ M\nh : α → M → N\nh_zero : ∀ (a : α), h a 0 = 1\nh_add : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ * h a b₂\n⊢ prod (f + g) h = prod f h * prod g h","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical ","nextTactic":"exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a","declUpToTactic":"/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.411_0.MEVUz78Vsm81fPx","decl":"/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddZeroClass M\ninst✝ : AddCommMonoid N\nF : α → M →+ N\n⊢ (fun F x => AddMonoidHom.comp F (singleAddHom x))\n ((fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x), map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) = (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) })\n F) =\n F","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : �� → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ","nextTactic":"ext","declUpToTactic":"/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.440_0.MEVUz78Vsm81fPx","decl":"/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F "} -{"state":"case h.h\nα : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddZeroClass M\ninst✝ : AddCommMonoid N\nF : α → M →+ N\nx✝¹ : α\nx✝ : M\n⊢ ((fun F x => AddMonoidHom.comp F (singleAddHom x))\n ((fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x), map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) = (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) })\n F)\n x✝¹)\n x✝ =\n (F x✝¹) x✝","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n ","nextTactic":"simp [singleAddHom]","declUpToTactic":"/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.440_0.MEVUz78Vsm81fPx","decl":"/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddZeroClass M\ninst✝ : AddCommMonoid N\nF : (α →₀ M) →+ N\n⊢ (fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x), map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) = (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) })\n ((fun F x => AddMonoidHom.comp F (singleAddHom x)) F) =\n F","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ��� pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n ","nextTactic":"apply Finsupp.addHom_ext'","declUpToTactic":"/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.440_0.MEVUz78Vsm81fPx","decl":"/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F "} -{"state":"case H\nα : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddZeroClass M\ninst✝ : AddCommMonoid N\nF : (α →₀ M) →+ N\n⊢ ∀ (x : α),\n AddMonoidHom.comp\n ((fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x), map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) = (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) })\n ((fun F x => AddMonoidHom.comp F (singleAddHom x)) F))\n (singleAddHom x) =\n AddMonoidHom.comp F (singleAddHom x)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n ","nextTactic":"simp [singleAddHom, AddMonoidHom.comp, Function.comp]","declUpToTactic":"/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.440_0.MEVUz78Vsm81fPx","decl":"/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG✝ : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddZeroClass M\ninst✝ : AddCommMonoid N\nF G : α → M →+ N\n⊢ Equiv.toFun\n {\n toFun := fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x), map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) = (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) },\n invFun := fun F x => AddMonoidHom.comp F (singleAddHom x),\n left_inv :=\n (_ :\n ∀ (F : α → M →+ N),\n (fun F x => AddMonoidHom.comp F (singleAddHom x))\n ((fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x),\n map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) = (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) })\n F) =\n F),\n right_inv :=\n (_ :\n ∀ (F : (α →₀ M) →+ N),\n (fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x),\n map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) = (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) })\n ((fun F x => AddMonoidHom.comp F (singleAddHom x)) F) =\n F) }\n (F + G) =\n Equiv.toFun\n {\n toFun := fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x), map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) = (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) },\n invFun := fun F x => AddMonoidHom.comp F (singleAddHom x),\n left_inv :=\n (_ :\n ∀ (F : α → M →+ N),\n (fun F x => AddMonoidHom.comp F (singleAddHom x))\n ((fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x),\n map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) = (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) })\n F) =\n F),\n right_inv :=\n (_ :\n ∀ (F : (α →₀ M) →+ N),\n (fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x),\n map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) = (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) })\n ((fun F x => AddMonoidHom.comp F (singleAddHom x)) F) =\n F) }\n F +\n Equiv.toFun\n {\n toFun := fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x), map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) = (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) },\n invFun := fun F x => AddMonoidHom.comp F (singleAddHom x),\n left_inv :=\n (_ :\n ∀ (F : α → M →+ N),\n (fun F x => AddMonoidHom.comp F (singleAddHom x))\n ((fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x),\n map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) = (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) })\n F) =\n F),\n right_inv :=\n (_ :\n ∀ (F : (α →₀ M) →+ N),\n (fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x),\n map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) = (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) })\n ((fun F x => AddMonoidHom.comp F (singleAddHom x)) F) =\n F) }\n G","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ","nextTactic":"ext x","declUpToTactic":"/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.440_0.MEVUz78Vsm81fPx","decl":"/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F "} -{"state":"case H.h\nα : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx✝¹ : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG✝ : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddZeroClass M\ninst✝ : AddCommMonoid N\nF G : α → M →+ N\nx : α\nx✝ : M\n⊢ (AddMonoidHom.comp\n (Equiv.toFun\n {\n toFun := fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x),\n map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) = (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) },\n invFun := fun F x => AddMonoidHom.comp F (singleAddHom x),\n left_inv :=\n (_ :\n ∀ (F : α → M →+ N),\n (fun F x => AddMonoidHom.comp F (singleAddHom x))\n ((fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x),\n map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) =\n (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) })\n F) =\n F),\n right_inv :=\n (_ :\n ∀ (F : (α →₀ M) →+ N),\n (fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x),\n map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) = (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) })\n ((fun F x => AddMonoidHom.comp F (singleAddHom x)) F) =\n F) }\n (F + G))\n (singleAddHom x))\n x✝ =\n (AddMonoidHom.comp\n (Equiv.toFun\n {\n toFun := fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x),\n map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) = (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) },\n invFun := fun F x => AddMonoidHom.comp F (singleAddHom x),\n left_inv :=\n (_ :\n ∀ (F : α → M →+ N),\n (fun F x => AddMonoidHom.comp F (singleAddHom x))\n ((fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x),\n map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) =\n (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) })\n F) =\n F),\n right_inv :=\n (_ :\n ∀ (F : (α →₀ M) →+ N),\n (fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x),\n map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) =\n (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) })\n ((fun F x => AddMonoidHom.comp F (singleAddHom x)) F) =\n F) }\n F +\n Equiv.toFun\n {\n toFun := fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x),\n map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) = (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) },\n invFun := fun F x => AddMonoidHom.comp F (singleAddHom x),\n left_inv :=\n (_ :\n ∀ (F : α → M →+ N),\n (fun F x => AddMonoidHom.comp F (singleAddHom x))\n ((fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x),\n map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) =\n (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) })\n F) =\n F),\n right_inv :=\n (_ :\n ∀ (F : (α →₀ M) →+ N),\n (fun F =>\n {\n toZeroHom :=\n { toFun := fun f => sum f fun x => ⇑(F x),\n map_zero' := (_ : ∑ x in ∅, (fun x => ⇑(F x)) x (0 x) = 0) },\n map_add' :=\n (_ :\n ∀ (x x_1 : α →₀ M),\n (sum (x + x_1) fun a => ⇑(F a)) =\n (sum x fun a => ⇑(F a)) + sum x_1 fun a => ⇑(F a)) })\n ((fun F x => AddMonoidHom.comp F (singleAddHom x)) F) =\n F) }\n G)\n (singleAddHom x))\n x✝","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n ","nextTactic":"exact sum_add","declUpToTactic":"/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.440_0.MEVUz78Vsm81fPx","decl":"/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : Fintype α\ninst✝ : AddCommMonoid M\nf : α →₀ M\n⊢ ∑ a : α, single a (f a) = f","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n ","nextTactic":"classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]","declUpToTactic":"/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.490_0.MEVUz78Vsm81fPx","decl":"/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : Fintype α\ninst✝ : AddCommMonoid M\nf : α →₀ M\n⊢ ∑ a : α, single a (f a) = f","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n ","nextTactic":"refine FunLike.coe_injective ?_","declUpToTactic":"/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.490_0.MEVUz78Vsm81fPx","decl":"/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : Fintype α\ninst✝ : AddCommMonoid M\nf : α →₀ M\n⊢ (fun f => ⇑f) (∑ a : α, single a (f a)) = (fun f => ⇑f) f","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n ","nextTactic":"simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]","declUpToTactic":"/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.490_0.MEVUz78Vsm81fPx","decl":"/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni✝ : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : Fintype α\ni : α\nm : M\n⊢ ∑ j : α, (single i m) j = m","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n ","nextTactic":"classical rw [single, coe_mk, Finset.sum_pi_single']","declUpToTactic":"@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.498_0.MEVUz78Vsm81fPx","decl":"@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni✝ : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : Fintype α\ni : α\nm : M\n⊢ ∑ j : α, (single i m) j = m","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical ","nextTactic":"rw [single, coe_mk, Finset.sum_pi_single']","declUpToTactic":"@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.498_0.MEVUz78Vsm81fPx","decl":"@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni✝ : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : Fintype α\ni : α\nm : M\n⊢ (if i ∈ univ then m else 0) = m","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n ","nextTactic":"simp","declUpToTactic":"@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.498_0.MEVUz78Vsm81fPx","decl":"@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni✝ : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : Fintype α\ni : α\nm : M\n⊢ ∑ j : α, (single j m) i = m","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n ","nextTactic":"simp_rw [single, coe_mk]","declUpToTactic":"@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.506_0.MEVUz78Vsm81fPx","decl":"@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni✝ : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : Fintype α\ni : α\nm : M\n⊢ ∑ x : α, Pi.single x m i = m","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n ","nextTactic":"classical rw [Finset.sum_pi_single]","declUpToTactic":"@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.506_0.MEVUz78Vsm81fPx","decl":"@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni✝ : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : Fintype α\ni : α\nm : M\n⊢ ∑ x : α, Pi.single x m i = m","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical ","nextTactic":"rw [Finset.sum_pi_single]","declUpToTactic":"@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.506_0.MEVUz78Vsm81fPx","decl":"@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni✝ : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : Fintype α\ni : α\nm : M\n⊢ (if i ∈ univ then m else 0) = m","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n ","nextTactic":"simp","declUpToTactic":"@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.506_0.MEVUz78Vsm81fPx","decl":"@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : Fintype α\ninst✝ : AddCommMonoid M\nf : α → M\n⊢ equivFunOnFinite.symm f = ∑ a : α, single a (f a)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n ","nextTactic":"rw [← univ_sum_single (equivFunOnFinite.symm f)]","declUpToTactic":"theorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.516_0.MEVUz78Vsm81fPx","decl":"theorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : Fintype α\ninst✝ : AddCommMonoid M\nf : α → M\n⊢ ∑ a : α, single a ((equivFunOnFinite.symm f) a) = ∑ a : α, single a (f a)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ","nextTactic":"ext","declUpToTactic":"theorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.516_0.MEVUz78Vsm81fPx","decl":"theorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) "} -{"state":"case h\nα : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : Fintype α\ninst✝ : AddCommMonoid M\nf : α → M\na✝ : α\n⊢ (∑ a : α, single a ((equivFunOnFinite.symm f) a)) a✝ = (∑ a : α, single a (f a)) a✝","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n ","nextTactic":"simp","declUpToTactic":"theorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.516_0.MEVUz78Vsm81fPx","decl":"theorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : AddCommMonoid M\ninst✝¹ : AddCommMonoid N\ninst✝ : AddCommMonoid P\ng : N →+ P\nf : α → M →+ N\na : α\n⊢ (AddEquiv.symm liftAddHom) (AddMonoidHom.comp g (liftAddHom f)) a = AddMonoidHom.comp g (f a)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n ","nextTactic":"rw [liftAddHom_symm_apply]","declUpToTactic":"theorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.535_0.MEVUz78Vsm81fPx","decl":"theorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : AddCommMonoid M\ninst✝¹ : AddCommMonoid N\ninst✝ : AddCommMonoid P\ng : N →+ P\nf : α → M →+ N\na : α\n⊢ AddMonoidHom.comp (AddMonoidHom.comp g (liftAddHom f)) (singleAddHom a) = AddMonoidHom.comp g (f a)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α ��₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n ","nextTactic":"rw [AddMonoidHom.comp_assoc]","declUpToTactic":"theorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.535_0.MEVUz78Vsm81fPx","decl":"theorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁵ : AddCommMonoid A\ninst✝⁴ : AddCommMonoid B\ninst✝³ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝² : AddCommMonoid M\ninst✝¹ : AddCommMonoid N\ninst✝ : AddCommMonoid P\ng : N →+ P\nf : α → M →+ N\na : α\n⊢ AddMonoidHom.comp g (AddMonoidHom.comp (liftAddHom f) (singleAddHom a)) = AddMonoidHom.comp g (f a)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n ","nextTactic":"rw [liftAddHom_comp_single]","declUpToTactic":"theorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.535_0.MEVUz78Vsm81fPx","decl":"theorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : Zero M\ninst✝ : CommMonoid N\nv : α →₀ M\nf : α ↪ β\ng : β → M → N\n⊢ prod (embDomain f v) g = prod v fun a b => g (f a) b","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n ","nextTactic":"rw [prod]","declUpToTactic":"@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.552_0.MEVUz78Vsm81fPx","decl":"@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : Zero M\ninst✝ : CommMonoid N\nv : α →₀ M\nf : α ↪ β\ng : β → M → N\n⊢ ∏ a in (embDomain f v).support, g a ((embDomain f v) a) = prod v fun a b => g (f a) b","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n ","nextTactic":"rw [prod]","declUpToTactic":"@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.552_0.MEVUz78Vsm81fPx","decl":"@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : Zero M\ninst✝ : CommMonoid N\nv : α →₀ M\nf : α ↪ β\ng : β → M → N\n⊢ ∏ a in (embDomain f v).support, g a ((embDomain f v) a) = ∏ a in v.support, g (f a) (v a)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n ","nextTactic":"rw [support_embDomain]","declUpToTactic":"@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.552_0.MEVUz78Vsm81fPx","decl":"@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : Zero M\ninst✝ : CommMonoid N\nv : α →₀ M\nf : α ↪ β\ng : β → M → N\n⊢ ∏ a in map f v.support, g a ((embDomain f v) a) = ∏ a in v.support, g (f a) (v a)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n ","nextTactic":"rw [Finset.prod_map]","declUpToTactic":"@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.552_0.MEVUz78Vsm81fPx","decl":"@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : Zero M\ninst✝ : CommMonoid N\nv : α →₀ M\nf : α ↪ β\ng : β → M → N\n⊢ ∏ x in v.support, g (f x) ((embDomain f v) (f x)) = ∏ a in v.support, g (f a) (v a)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n ","nextTactic":"simp_rw [embDomain_apply]","declUpToTactic":"@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.552_0.MEVUz78Vsm81fPx","decl":"@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝¹ : Finset α\nf : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : CommMonoid N\ns✝ : Finset ι\ng : ι → α →₀ M\nh : α → M → N\nh_zero : ∀ (a : α), h a 0 = 1\nh_add : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ * h a b₂\na : ι\ns : Finset ι\nhas : a ∉ s\nih : ∏ i in s, prod (g i) h = prod (∑ i in s, g i) h\n⊢ ∏ i in Finset.cons a s has, prod (g i) h = prod (∑ i in Finset.cons a s has, g i) h","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n ","nextTactic":"rw [prod_cons]","declUpToTactic":"@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.563_0.MEVUz78Vsm81fPx","decl":"@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝¹ : Finset α\nf : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : CommMonoid N\ns✝ : Finset ι\ng : ι → α →₀ M\nh : α → M → N\nh_zero : ∀ (a : α), h a 0 = 1\nh_add : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ * h a b₂\na : ι\ns : Finset ι\nhas : a ∉ s\nih : ∏ i in s, prod (g i) h = prod (∑ i in s, g i) h\n⊢ prod (g a) h * ∏ x in s, prod (g x) h = prod (∑ i in Finset.cons a s has, g i) h","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n ","nextTactic":"rw [ih]","declUpToTactic":"@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.563_0.MEVUz78Vsm81fPx","decl":"@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝¹ : Finset α\nf : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : CommMonoid N\ns✝ : Finset ι\ng : ι → α →₀ M\nh : α → M → N\nh_zero : ∀ (a : α), h a 0 = 1\nh_add : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ * h a b₂\na : ι\ns : Finset ι\nhas : a ∉ s\nih : ∏ i in s, prod (g i) h = prod (∑ i in s, g i) h\n⊢ prod (g a) h * prod (∑ i in s, g i) h = prod (∑ i in Finset.cons a s has, g i) h","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n ","nextTactic":"rw [sum_cons]","declUpToTactic":"@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.563_0.MEVUz78Vsm81fPx","decl":"@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝¹ : Finset α\nf : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : CommMonoid N\ns✝ : Finset ι\ng : ι → α →₀ M\nh : α → M → N\nh_zero : ∀ (a : α), h a 0 = 1\nh_add : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ * h a b₂\na : ι\ns : Finset ι\nhas : a ∉ s\nih : ∏ i in s, prod (g i) h = prod (∑ i in s, g i) h\n⊢ prod (g a) h * prod (∑ i in s, g i) h = prod (g a + ∑ x in s, g x) h","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : �� → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n ","nextTactic":"rw [prod_add_index' h_zero h_add]","declUpToTactic":"@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.563_0.MEVUz78Vsm81fPx","decl":"@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : AddCommMonoid N\nf : Multiset (α →₀ M)\nh : α → M → N\nh₀ : ∀ (a : α), h a 0 = 0\nh₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂\na : α →₀ M\ns : Multiset (α →₀ M)\nih : sum (Multiset.sum s) h = Multiset.sum (Multiset.map (fun g => sum g h) s)\n⊢ sum (Multiset.sum (a ::ₘ s)) h = Multiset.sum (Multiset.map (fun g => sum g h) (a ::ₘ s))","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n ","nextTactic":"rw [Multiset.sum_cons]","declUpToTactic":"theorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.584_0.MEVUz78Vsm81fPx","decl":"theorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : AddCommMonoid N\nf : Multiset (α →₀ M)\nh : α → M → N\nh₀ : ∀ (a : α), h a 0 = 0\nh₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂\na : α →₀ M\ns : Multiset (α →₀ M)\nih : sum (Multiset.sum s) h = Multiset.sum (Multiset.map (fun g => sum g h) s)\n⊢ sum (a + Multiset.sum s) h = Multiset.sum (Multiset.map (fun g => sum g h) (a ::ₘ s))","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n ","nextTactic":"rw [Multiset.map_cons]","declUpToTactic":"theorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.584_0.MEVUz78Vsm81fPx","decl":"theorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : AddCommMonoid N\nf : Multiset (α →₀ M)\nh : α → M → N\nh₀ : ∀ (a : α), h a 0 = 0\nh₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂\na : α →₀ M\ns : Multiset (α →₀ M)\nih : sum (Multiset.sum s) h = Multiset.sum (Multiset.map (fun g => sum g h) s)\n⊢ sum (a + Multiset.sum s) h = Multiset.sum (sum a h ::ₘ Multiset.map (fun g => sum g h) s)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n ","nextTactic":"rw [Multiset.sum_cons]","declUpToTactic":"theorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.584_0.MEVUz78Vsm81fPx","decl":"theorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : AddCommMonoid N\nf : Multiset (α →₀ M)\nh : α → M → N\nh₀ : ∀ (a : α), h a 0 = 0\nh₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂\na : α →₀ M\ns : Multiset (α →₀ M)\nih : sum (Multiset.sum s) h = Multiset.sum (Multiset.map (fun g => sum g h) s)\n⊢ sum (a + Multiset.sum s) h = sum a h + Multiset.sum (Multiset.map (fun g => sum g h) s)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n ","nextTactic":"rw [sum_add_index' h₀ h₁]","declUpToTactic":"theorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.584_0.MEVUz78Vsm81fPx","decl":"theorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : AddCommMonoid N\nf : Multiset (α →₀ M)\nh : α → M → N\nh₀ : ∀ (a : α), h a 0 = 0\nh₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂\na : α →₀ M\ns : Multiset (α →₀ M)\nih : sum (Multiset.sum s) h = Multiset.sum (Multiset.map (fun g => sum g h) s)\n⊢ ((sum a fun a => h a) + sum (Multiset.sum s) fun a => h a) =\n sum a h + Multiset.sum (Multiset.map (fun g => sum g h) s)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n ","nextTactic":"rw [ih]","declUpToTactic":"theorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.584_0.MEVUz78Vsm81fPx","decl":"theorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum "} -{"state":"α✝ : Type u_1\nι✝ : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι✝ → A → C\nh0 : ∀ (i : ι✝), t i 0 = 0\nh1 : ∀ (i : ι✝) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α✝\nf : α✝ → ι✝ →₀ A\ni : ι✝\ng✝ : ι✝ →₀ A\nk : ι✝ → A → γ → B\nx : γ\nβ : Type u_7\nM✝ : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\nα : Type u_16\nι : Type u_17\nM : Type u_18\ninst✝¹ : DecidableEq α\ninst✝ : AddCommMonoid M\ng : ι → α →₀ M\ns : Finset ι\nh : ∀ (i₁ i₂ : ι), i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support\n⊢ (∑ i in s, g i).support = Finset.biUnion s fun i => (g i).support","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n ","nextTactic":"classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm","declUpToTactic":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.596_0.MEVUz78Vsm81fPx","decl":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support "} -{"state":"α✝ : Type u_1\nι✝ : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι✝ → A → C\nh0 : ∀ (i : ι✝), t i 0 = 0\nh1 : ∀ (i : ι✝) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α✝\nf : α✝ → ι✝ →₀ A\ni : ι✝\ng✝ : ι✝ →₀ A\nk : ι✝ → A → γ → B\nx : γ\nβ : Type u_7\nM✝ : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\nα : Type u_16\nι : Type u_17\nM : Type u_18\ninst✝¹ : DecidableEq α\ninst✝ : AddCommMonoid M\ng : ι → α →₀ M\ns : Finset ι\nh : ∀ (i₁ i₂ : ι), i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support\n⊢ (∑ i in s, g i).support = Finset.biUnion s fun i => (g i).support","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n ","nextTactic":"refine Finset.induction_on s ?_ ?_","declUpToTactic":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.596_0.MEVUz78Vsm81fPx","decl":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support "} -{"state":"case refine_1\nα✝ : Type u_1\nι✝ : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι✝ → A → C\nh0 : ∀ (i : ι✝), t i 0 = 0\nh1 : ∀ (i : ι✝) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α✝\nf : α✝ → ι✝ →₀ A\ni : ι✝\ng✝ : ι✝ →₀ A\nk : ι✝ → A → γ → B\nx : γ\nβ : Type u_7\nM✝ : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\nα : Type u_16\nι : Type u_17\nM : Type u_18\ninst✝¹ : DecidableEq α\ninst✝ : AddCommMonoid M\ng : ι → α →₀ M\ns : Finset ι\nh : ∀ (i₁ i₂ : ι), i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support\n⊢ (∑ i in ∅, g i).support = Finset.biUnion ∅ fun i => (g i).support","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · ","nextTactic":"simp","declUpToTactic":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.596_0.MEVUz78Vsm81fPx","decl":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support "} -{"state":"case refine_2\nα✝ : Type u_1\nι✝ : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι✝ → A → C\nh0 : ∀ (i : ι✝), t i 0 = 0\nh1 : ∀ (i : ι✝) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α✝\nf : α✝ → ι✝ →₀ A\ni : ι✝\ng✝ : ι✝ →₀ A\nk : ι✝ → A → γ → B\nx : γ\nβ : Type u_7\nM✝ : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\nα : Type u_16\nι : Type u_17\nM : Type u_18\ninst✝¹ : DecidableEq α\ninst✝ : AddCommMonoid M\ng : ι → α →₀ M\ns : Finset ι\nh : ∀ (i₁ i₂ : ι), i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support\n⊢ ∀ ⦃a : ι⦄ {s : Finset ι},\n a ∉ s →\n ((∑ i in s, g i).support = Finset.biUnion s fun i => (g i).support) →\n (∑ i in insert a s, g i).support = Finset.biUnion (insert a s) fun i => (g i).support","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · ","nextTactic":"intro i s hi","declUpToTactic":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.596_0.MEVUz78Vsm81fPx","decl":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support "} -{"state":"case refine_2\nα✝ : Type u_1\nι✝ : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι✝ → A → C\nh0 : ∀ (i : ι✝), t i 0 = 0\nh1 : ∀ (i : ι✝) (x y : A), t i (x + y) = t i x + t i y\ns✝¹ : Finset α✝\nf : α✝ → ι✝ →₀ A\ni✝ : ι✝\ng✝ : ι✝ →₀ A\nk : ι✝ → A → γ → B\nx : γ\nβ : Type u_7\nM✝ : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\nα : Type u_16\nι : Type u_17\nM : Type u_18\ninst✝¹ : DecidableEq α\ninst✝ : AddCommMonoid M\ng : ι → α →₀ M\ns✝ : Finset ι\nh : ∀ (i₁ i₂ : ι), i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support\ni : ι\ns : Finset ι\nhi : i ∉ s\n⊢ ((∑ i in s, g i).support = Finset.biUnion s fun i => (g i).support) →\n (∑ i in insert i s, g i).support = Finset.biUnion (insert i s) fun i => (g i).support","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n ","nextTactic":"simp only [hi, sum_insert, not_false_iff, biUnion_insert]","declUpToTactic":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.596_0.MEVUz78Vsm81fPx","decl":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support "} -{"state":"case refine_2\nα✝ : Type u_1\nι✝ : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι✝ → A → C\nh0 : ∀ (i : ι✝), t i 0 = 0\nh1 : ∀ (i : ι✝) (x y : A), t i (x + y) = t i x + t i y\ns✝¹ : Finset α✝\nf : α✝ → ι✝ →₀ A\ni✝ : ι✝\ng✝ : ι✝ →₀ A\nk : ι✝ → A → γ → B\nx : γ\nβ : Type u_7\nM✝ : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\nα : Type u_16\nι : Type u_17\nM : Type u_18\ninst✝¹ : DecidableEq α\ninst✝ : AddCommMonoid M\ng : ι → α →₀ M\ns✝ : Finset ι\nh : ∀ (i₁ i₂ : ι), i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support\ni : ι\ns : Finset ι\nhi : i ∉ s\n⊢ ((∑ i in s, g i).support = Finset.biUnion s fun i => (g i).support) →\n (g i + ∑ i in s, g i).support = (g i).support ∪ Finset.biUnion s fun i => (g i).support","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n ","nextTactic":"intro hs","declUpToTactic":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.596_0.MEVUz78Vsm81fPx","decl":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support "} -{"state":"case refine_2\nα✝ : Type u_1\nι✝ : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι✝ → A → C\nh0 : ∀ (i : ι✝), t i 0 = 0\nh1 : ∀ (i : ι✝) (x y : A), t i (x + y) = t i x + t i y\ns✝¹ : Finset α✝\nf : α✝ → ι✝ →₀ A\ni✝ : ι✝\ng✝ : ι✝ →₀ A\nk : ι✝ → A → γ → B\nx : γ\nβ : Type u_7\nM✝ : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\nα : Type u_16\nι : Type u_17\nM : Type u_18\ninst✝¹ : DecidableEq α\ninst✝ : AddCommMonoid M\ng : ι → α →₀ M\ns✝ : Finset ι\nh : ∀ (i₁ i₂ : ι), i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support\ni : ι\ns : Finset ι\nhi : i ∉ s\nhs : (∑ i in s, g i).support = Finset.biUnion s fun i => (g i).support\n⊢ (g i + ∑ i in s, g i).support = (g i).support ∪ Finset.biUnion s fun i => (g i).support","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n ","nextTactic":"rw [Finsupp.support_add_eq]","declUpToTactic":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.596_0.MEVUz78Vsm81fPx","decl":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support "} -{"state":"case refine_2\nα✝ : Type u_1\nι✝ : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι✝ → A → C\nh0 : ∀ (i : ι✝), t i 0 = 0\nh1 : ∀ (i : ι✝) (x y : A), t i (x + y) = t i x + t i y\ns✝¹ : Finset α✝\nf : α✝ → ι✝ →₀ A\ni✝ : ι✝\ng✝ : ι✝ →₀ A\nk : ι✝ → A → γ → B\nx : γ\nβ : Type u_7\nM✝ : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\nα : Type u_16\nι : Type u_17\nM : Type u_18\ninst✝¹ : DecidableEq α\ninst✝ : AddCommMonoid M\ng : ι → α →₀ M\ns✝ : Finset ι\nh : ∀ (i₁ i₂ : ι), i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support\ni : ι\ns : Finset ι\nhi : i ∉ s\nhs : (∑ i in s, g i).support = Finset.biUnion s fun i => (g i).support\n⊢ (g i).support ∪ (∑ i in s, g i).support = (g i).support ∪ Finset.biUnion s fun i => (g i).support\ncase refine_2\nα✝ : Type u_1\nι✝ : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι✝ → A → C\nh0 : ∀ (i : ι✝), t i 0 = 0\nh1 : ∀ (i : ι✝) (x y : A), t i (x + y) = t i x + t i y\ns✝¹ : Finset α✝\nf : α✝ → ι✝ →₀ A\ni✝ : ι✝\ng✝ : ι✝ →₀ A\nk : ι✝ → A → γ → B\nx : γ\nβ : Type u_7\nM✝ : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\nα : Type u_16\nι : Type u_17\nM : Type u_18\ninst✝¹ : DecidableEq α\ninst✝ : AddCommMonoid M\ng : ι → α →₀ M\ns✝ : Finset ι\nh : ∀ (i₁ i₂ : ι), i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support\ni : ι\ns : Finset ι\nhi : i ∉ s\nhs : (∑ i in s, g i).support = Finset.biUnion s fun i => (g i).support\n⊢ Disjoint (g i).support (∑ i in s, g i).support","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n ","nextTactic":"rw [hs]","declUpToTactic":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.596_0.MEVUz78Vsm81fPx","decl":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support "} -{"state":"case refine_2\nα✝ : Type u_1\nι✝ : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι✝ → A → C\nh0 : ∀ (i : ι✝), t i 0 = 0\nh1 : ∀ (i : ι✝) (x y : A), t i (x + y) = t i x + t i y\ns✝¹ : Finset α✝\nf : α✝ → ι✝ →₀ A\ni✝ : ι✝\ng✝ : ι✝ →₀ A\nk : ι✝ → A → γ → B\nx : γ\nβ : Type u_7\nM✝ : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\nα : Type u_16\nι : Type u_17\nM : Type u_18\ninst✝¹ : DecidableEq α\ninst✝ : AddCommMonoid M\ng : ι → α →₀ M\ns✝ : Finset ι\nh : ∀ (i₁ i₂ : ι), i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support\ni : ι\ns : Finset ι\nhi : i ∉ s\nhs : (∑ i in s, g i).support = Finset.biUnion s fun i => (g i).support\n⊢ Disjoint (g i).support (∑ i in s, g i).support","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h�� a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n ","nextTactic":"rw [hs]","declUpToTactic":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.596_0.MEVUz78Vsm81fPx","decl":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support "} -{"state":"case refine_2\nα✝ : Type u_1\nι✝ : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι✝ → A → C\nh0 : ∀ (i : ι✝), t i 0 = 0\nh1 : ∀ (i : ι✝) (x y : A), t i (x + y) = t i x + t i y\ns✝¹ : Finset α✝\nf : α✝ → ι✝ →₀ A\ni✝ : ι✝\ng✝ : ι✝ →₀ A\nk : ι✝ → A → γ → B\nx : γ\nβ : Type u_7\nM✝ : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\nα : Type u_16\nι : Type u_17\nM : Type u_18\ninst✝¹ : DecidableEq α\ninst✝ : AddCommMonoid M\ng : ι → α →₀ M\ns✝ : Finset ι\nh : ∀ (i₁ i₂ : ι), i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support\ni : ι\ns : Finset ι\nhi : i ∉ s\nhs : (∑ i in s, g i).support = Finset.biUnion s fun i => (g i).support\n⊢ Disjoint (g i).support (Finset.biUnion s fun i => (g i).support)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n ","nextTactic":"rw [Finset.disjoint_biUnion_right]","declUpToTactic":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.596_0.MEVUz78Vsm81fPx","decl":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support "} -{"state":"case refine_2\nα✝ : Type u_1\nι✝ : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι✝ → A → C\nh0 : ∀ (i : ι✝), t i 0 = 0\nh1 : ∀ (i : ι✝) (x y : A), t i (x + y) = t i x + t i y\ns✝¹ : Finset α✝\nf : α✝ → ι✝ →₀ A\ni✝ : ι✝\ng✝ : ι✝ →₀ A\nk : ι✝ → A → γ → B\nx : γ\nβ : Type u_7\nM✝ : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\nα : Type u_16\nι : Type u_17\nM : Type u_18\ninst✝¹ : DecidableEq α\ninst✝ : AddCommMonoid M\ng : ι → α →₀ M\ns✝ : Finset ι\nh : ∀ (i₁ i₂ : ι), i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support\ni : ι\ns : Finset ι\nhi : i ∉ s\nhs : (∑ i in s, g i).support = Finset.biUnion s fun i => (g i).support\n⊢ ∀ i_1 ∈ s, Disjoint (g i).support (g i_1).support","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b���), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n ","nextTactic":"intro j hj","declUpToTactic":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.596_0.MEVUz78Vsm81fPx","decl":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support "} -{"state":"case refine_2\nα✝ : Type u_1\nι✝ : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι✝ → A → C\nh0 : ∀ (i : ι✝), t i 0 = 0\nh1 : ∀ (i : ι✝) (x y : A), t i (x + y) = t i x + t i y\ns✝¹ : Finset α✝\nf : α✝ → ι✝ →₀ A\ni✝ : ι✝\ng✝ : ι✝ →₀ A\nk : ι✝ → A → γ → B\nx : γ\nβ : Type u_7\nM✝ : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\nα : Type u_16\nι : Type u_17\nM : Type u_18\ninst✝¹ : DecidableEq α\ninst✝ : AddCommMonoid M\ng : ι → α →₀ M\ns✝ : Finset ι\nh : ∀ (i₁ i₂ : ι), i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support\ni : ι\ns : Finset ι\nhi : i ∉ s\nhs : (∑ i in s, g i).support = Finset.biUnion s fun i => (g i).support\nj : ι\nhj : j ∈ s\n⊢ Disjoint (g i).support (g j).support","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n ","nextTactic":"refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm","declUpToTactic":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.596_0.MEVUz78Vsm81fPx","decl":"theorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ✝ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\nf1 f2 : α →₀ M\nhd : Disjoint f1.support f2.support\nβ : Type u_16\ninst✝ : CommMonoid β\ng : α → M → β\n⊢ prod (f1 + f2) g = prod f1 g * prod f2 g","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n ","nextTactic":"have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]","declUpToTactic":"/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.625_0.MEVUz78Vsm81fPx","decl":"/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx✝ : γ\nβ✝ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\nf1 f2 : α →₀ M\nhd✝ : Disjoint f1.support f2.support\nβ : Type u_16\ninst✝ : CommMonoid β\ng : α → M → β\nf1✝ f2✝ : α →₀ M\nhd : Disjoint f1✝.support f2✝.support\nx : α\nhx : x ∈ f1✝.support\n⊢ g x (f1✝ x + f2✝ x) = g x (f1✝ x)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n ","nextTactic":"simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]","declUpToTactic":"/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.625_0.MEVUz78Vsm81fPx","decl":"/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ✝ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\nf1 f2 : α →₀ M\nhd : Disjoint f1.support f2.support\nβ : Type u_16\ninst✝ : CommMonoid β\ng : α → M → β\nthis : ∀ {f1 f2 : α →₀ M}, Disjoint f1.support f2.support → ∏ x in f1.support, g x (f1 x + f2 x) = prod f1 g\n⊢ prod (f1 + f2) g = prod f1 g * prod f2 g","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n ","nextTactic":"classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]","declUpToTactic":"/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.625_0.MEVUz78Vsm81fPx","decl":"/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni : ι\ng✝ : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ✝ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\nf1 f2 : α →₀ M\nhd : Disjoint f1.support f2.support\nβ : Type u_16\ninst✝ : CommMonoid β\ng : α → M → β\nthis : ∀ {f1 f2 : α →₀ M}, Disjoint f1.support f2.support → ∏ x in f1.support, g x (f1 x + f2 x) = prod f1 g\n⊢ prod (f1 + f2) g = prod f1 g * prod f2 g","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical ","nextTactic":"simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]","declUpToTactic":"/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.625_0.MEVUz78Vsm81fPx","decl":"/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1✝ : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : CommMonoid N\nf1 f2 : α →₀ M\ng1 g2 : α → M → N\nh1 : f1.support ⊆ f2.support\nh2 : ∀ a ∈ f1.support, g1 a (f1 a) ∣ g2 a (f2 a)\n⊢ prod f1 g1 ∣ prod f2 g2","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : �� → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ��� f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n ","nextTactic":"classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2","declUpToTactic":"theorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.644_0.MEVUz78Vsm81fPx","decl":"theorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1✝ : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : CommMonoid N\nf1 f2 : α →₀ M\ng1 g2 : α → M → N\nh1 : f1.support ⊆ f2.support\nh2 : ∀ a ∈ f1.support, g1 a (f1 a) ∣ g2 a (f2 a)\n⊢ prod f1 g1 ∣ prod f2 g2","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n ","nextTactic":"simp only [Finsupp.prod, Finsupp.prod_mul]","declUpToTactic":"theorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.644_0.MEVUz78Vsm81fPx","decl":"theorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1✝ : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : CommMonoid N\nf1 f2 : α →₀ M\ng1 g2 : α → M → N\nh1 : f1.support ⊆ f2.support\nh2 : ∀ a ∈ f1.support, g1 a (f1 a) ∣ g2 a (f2 a)\n⊢ ∏ a in f1.support, g1 a (f1 a) ∣ ∏ a in f2.support, g2 a (f2 a)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n ","nextTactic":"rw [← sdiff_union_of_subset h1]","declUpToTactic":"theorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.644_0.MEVUz78Vsm81fPx","decl":"theorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1✝ : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : CommMonoid N\nf1 f2 : α →₀ M\ng1 g2 : α → M → N\nh1 : f1.support ⊆ f2.support\nh2 : ∀ a ∈ f1.support, g1 a (f1 a) ∣ g2 a (f2 a)\n⊢ ∏ a in f1.support, g1 a (f1 a) ∣ ∏ a in f2.support \\ f1.support ∪ f1.support, g2 a (f2 a)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : �� → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n ","nextTactic":"rw [prod_union sdiff_disjoint]","declUpToTactic":"theorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.644_0.MEVUz78Vsm81fPx","decl":"theorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1✝ : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : CommMonoid N\nf1 f2 : α →₀ M\ng1 g2 : α → M → N\nh1 : f1.support ⊆ f2.support\nh2 : ∀ a ∈ f1.support, g1 a (f1 a) ∣ g2 a (f2 a)\n⊢ ∏ a in f1.support, g1 a (f1 a) ∣ (∏ x in f2.support \\ f1.support, g2 x (f2 x)) * ∏ x in f1.support, g2 x (f2 x)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n ","nextTactic":"apply dvd_mul_of_dvd_right","declUpToTactic":"theorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.644_0.MEVUz78Vsm81fPx","decl":"theorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 "} -{"state":"case h\nα : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1✝ : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : CommMonoid N\nf1 f2 : α →₀ M\ng1 g2 : α → M → N\nh1 : f1.support ⊆ f2.support\nh2 : ∀ a ∈ f1.support, g1 a (f1 a) ∣ g2 a (f2 a)\n⊢ ∏ a in f1.support, g1 a (f1 a) ∣ ∏ x in f1.support, g2 x (f2 x)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n ","nextTactic":"apply prod_dvd_prod_of_dvd","declUpToTactic":"theorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.644_0.MEVUz78Vsm81fPx","decl":"theorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 "} -{"state":"case h.h\nα : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1✝ : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : CommMonoid N\nf1 f2 : α →₀ M\ng1 g2 : α → M → N\nh1 : f1.support ⊆ f2.support\nh2 : ∀ a ∈ f1.support, g1 a (f1 a) ∣ g2 a (f2 a)\n⊢ ∀ a ∈ f1.support, g1 a (f1 a) ∣ g2 a (f2 a)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n ","nextTactic":"exact h2","declUpToTactic":"theorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.644_0.MEVUz78Vsm81fPx","decl":"theorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\ns : Finset α\nf : (a : α) → a ∈ s → M\n⊢ indicator s f = ∑ x in attach s, single (↑x) (f ↑x (_ : ↑x ∈ s))","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n ","nextTactic":"rw [← sum_single (indicator s f)]","declUpToTactic":"lemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.656_0.MEVUz78Vsm81fPx","decl":"lemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\ns : Finset α\nf : (a : α) → a ∈ s → M\n⊢ sum (indicator s f) single = ∑ x in attach s, single (↑x) (f ↑x (_ : ↑x ∈ s))","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n ","nextTactic":"rw [sum]","declUpToTactic":"lemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.656_0.MEVUz78Vsm81fPx","decl":"lemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\ns : Finset α\nf : (a : α) → a ∈ s → M\n⊢ ∑ a in (indicator s f).support, single a ((indicator s f) a) = ∑ x in attach s, single (↑x) (f ↑x (_ : ↑x ∈ s))","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n ","nextTactic":"rw [sum_subset (support_indicator_subset _ _)]","declUpToTactic":"lemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.656_0.MEVUz78Vsm81fPx","decl":"lemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\ns : Finset α\nf : (a : α) → a ∈ s → M\n⊢ ∑ x in s, single x ((indicator s f) x) = ∑ x in attach s, single (↑x) (f ↑x (_ : ↑x ∈ s))\nα : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\ns : Finset α\nf : (a : α) → a ∈ s → M\n⊢ ∀ x ∈ s, x ∉ (indicator s f).support → single x ((indicator s f) x) = 0","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n ","nextTactic":"rw [← sum_attach]","declUpToTactic":"lemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.656_0.MEVUz78Vsm81fPx","decl":"lemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\ns : Finset α\nf : (a : α) → a ∈ s → M\n⊢ ∑ x in attach s, single (↑x) ((indicator s f) ↑x) = ∑ x in attach s, single (↑x) (f ↑x (_ : ↑x ∈ s))","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n �� apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · ","nextTactic":"refine' Finset.sum_congr rfl (fun _ _ => _)","declUpToTactic":"lemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.656_0.MEVUz78Vsm81fPx","decl":"lemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\ns : Finset α\nf : (a : α) → a ∈ s → M\nx✝¹ : { x // x ∈ s }\nx✝ : x✝¹ ∈ attach s\n⊢ single (↑x✝¹) ((indicator s f) ↑x✝¹) = single (↑x✝¹) (f ↑x✝¹ (_ : ↑x✝¹ ∈ s))","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n ","nextTactic":"rw [indicator_of_mem]","declUpToTactic":"lemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.656_0.MEVUz78Vsm81fPx","decl":"lemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\ns : Finset α\nf : (a : α) → a ∈ s → M\n⊢ ∀ x ∈ s, x ∉ (indicator s f).support → single x ((indicator s f) x) = 0","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : �� → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · ","nextTactic":"intro i _ hi","declUpToTactic":"lemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.656_0.MEVUz78Vsm81fPx","decl":"lemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni✝ : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\ns : Finset α\nf : (a : α) → a ∈ s → M\ni : α\na✝ : i ∈ s\nhi : i ∉ (indicator s f).support\n⊢ single i ((indicator s f) i) = 0","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb��� hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ��� a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n ","nextTactic":"rw [not_mem_support_iff.mp hi]","declUpToTactic":"lemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.656_0.MEVUz78Vsm81fPx","decl":"lemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni✝ : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\ns : Finset α\nf : (a : α) → a ∈ s → M\ni : α\na✝ : i ∈ s\nhi : i ∉ (indicator s f).support\n⊢ single i 0 = 0","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n rw [not_mem_support_iff.mp hi]\n ","nextTactic":"rw [single_zero]","declUpToTactic":"lemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n rw [not_mem_support_iff.mp hi]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.656_0.MEVUz78Vsm81fPx","decl":"lemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : Zero M\ninst✝ : CommMonoid N\ns : Finset α\nf : (a : α) → a ∈ s → M\nh : α → M → N\nh_zero : ∀ a ∈ s, h a 0 = 1\n⊢ prod (indicator s f) h = ∏ x in attach s, h (↑x) (f ↑x (_ : ↑x ∈ s))","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n rw [not_mem_support_iff.mp hi]\n rw [single_zero]\n#align finsupp.indicator_eq_sum_single Finsupp.indicator_eq_sum_attach_single\n\nlemma indicator_eq_sum_single [AddCommMonoid M] (s : Finset α) (f : α → M) :\n indicator s (fun x _ ↦ f x) = ∑ x in s, single x (f x) :=\n (indicator_eq_sum_attach_single _).trans <| sum_attach (f := fun x ↦ single x (f x))\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n ","nextTactic":"rw [prod_of_support_subset _ (support_indicator_subset _ _) h h_zero]","declUpToTactic":"@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.673_0.MEVUz78Vsm81fPx","decl":"@[to_additive (attr "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : Zero M\ninst✝ : CommMonoid N\ns : Finset α\nf : (a : α) → a ∈ s → M\nh : α → M → N\nh_zero : ∀ a ∈ s, h a 0 = 1\n⊢ ∏ x in s, h x ((indicator s f) x) = ∏ x in attach s, h (↑x) (f ↑x (_ : ↑x ∈ s))","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n rw [not_mem_support_iff.mp hi]\n rw [single_zero]\n#align finsupp.indicator_eq_sum_single Finsupp.indicator_eq_sum_attach_single\n\nlemma indicator_eq_sum_single [AddCommMonoid M] (s : Finset α) (f : α → M) :\n indicator s (fun x _ ↦ f x) = ∑ x in s, single x (f x) :=\n (indicator_eq_sum_attach_single _).trans <| sum_attach (f := fun x ↦ single x (f x))\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n rw [prod_of_support_subset _ (support_indicator_subset _ _) h h_zero]\n ","nextTactic":"rw [← prod_attach]","declUpToTactic":"@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n rw [prod_of_support_subset _ (support_indicator_subset _ _) h h_zero]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.673_0.MEVUz78Vsm81fPx","decl":"@[to_additive (attr "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : Zero M\ninst✝ : CommMonoid N\ns : Finset α\nf : (a : α) → a ∈ s → M\nh : α → M → N\nh_zero : ∀ a ∈ s, h a 0 = 1\n⊢ ∏ x in attach s, h (↑x) ((indicator s f) ↑x) = ∏ x in attach s, h (↑x) (f ↑x (_ : ↑x ∈ s))","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n rw [not_mem_support_iff.mp hi]\n rw [single_zero]\n#align finsupp.indicator_eq_sum_single Finsupp.indicator_eq_sum_attach_single\n\nlemma indicator_eq_sum_single [AddCommMonoid M] (s : Finset α) (f : α → M) :\n indicator s (fun x _ ↦ f x) = ∑ x in s, single x (f x) :=\n (indicator_eq_sum_attach_single _).trans <| sum_attach (f := fun x ↦ single x (f x))\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n rw [prod_of_support_subset _ (support_indicator_subset _ _) h h_zero]\n rw [← prod_attach]\n ","nextTactic":"refine' Finset.prod_congr rfl (fun _ _ => _)","declUpToTactic":"@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n rw [prod_of_support_subset _ (support_indicator_subset _ _) h h_zero]\n rw [← prod_attach]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.673_0.MEVUz78Vsm81fPx","decl":"@[to_additive (attr "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : Zero M\ninst✝ : CommMonoid N\ns : Finset α\nf : (a : α) → a ∈ s → M\nh : α → M → N\nh_zero : ∀ a ∈ s, h a 0 = 1\nx✝¹ : { x // x ∈ s }\nx✝ : x✝¹ ∈ attach s\n⊢ h (↑x✝¹) ((indicator s f) ↑x✝¹) = h (↑x✝¹) (f ↑x✝¹ (_ : ↑x✝¹ ∈ s))","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n rw [not_mem_support_iff.mp hi]\n rw [single_zero]\n#align finsupp.indicator_eq_sum_single Finsupp.indicator_eq_sum_attach_single\n\nlemma indicator_eq_sum_single [AddCommMonoid M] (s : Finset α) (f : α → M) :\n indicator s (fun x _ ↦ f x) = ∑ x in s, single x (f x) :=\n (indicator_eq_sum_attach_single _).trans <| sum_attach (f := fun x ↦ single x (f x))\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n rw [prod_of_support_subset _ (support_indicator_subset _ _) h h_zero]\n rw [← prod_attach]\n refine' Finset.prod_congr rfl (fun _ _ => _)\n ","nextTactic":"rw [indicator_of_mem]","declUpToTactic":"@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n rw [prod_of_support_subset _ (support_indicator_subset _ _) h h_zero]\n rw [← prod_attach]\n refine' Finset.prod_congr rfl (fun _ _ => _)\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.673_0.MEVUz78Vsm81fPx","decl":"@[to_additive (attr "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni✝ : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\nn : ℕ\nσ : Fin n →₀ M\ni : M\n⊢ (sum (cons i σ) fun x e => e) = i + sum σ fun x e => e","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support ��� (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n rw [not_mem_support_iff.mp hi]\n rw [single_zero]\n#align finsupp.indicator_eq_sum_single Finsupp.indicator_eq_sum_attach_single\n\nlemma indicator_eq_sum_single [AddCommMonoid M] (s : Finset α) (f : α → M) :\n indicator s (fun x _ ↦ f x) = ∑ x in s, single x (f x) :=\n (indicator_eq_sum_attach_single _).trans <| sum_attach (f := fun x ↦ single x (f x))\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n rw [prod_of_support_subset _ (support_indicator_subset _ _) h h_zero]\n rw [← prod_attach]\n refine' Finset.prod_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n#align finsupp.prod_indicator_index Finsupp.prod_indicator_index_eq_prod_attach\n#align finsupp.sum_indicator_index Finsupp.sum_indicator_index_eq_sum_attach\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index [Zero M] [CommMonoid N]\n {s : Finset α} (f : α → M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s (fun x _ ↦ f x)).prod h = ∏ x in s, h x (f x) :=\n (prod_indicator_index_eq_prod_attach _ h_zero).trans <| prod_attach (f := fun x ↦ h x (f x))\n\nlemma sum_cons [AddCommMonoid M] (n : ℕ) (σ : Fin n →₀ M) (i : M) :\n (sum (cons i σ) fun _ e ↦ e) = i + sum σ (fun _ e ↦ e) := by\n ","nextTactic":"rw [sum_fintype _ _ (fun _ => rfl)]","declUpToTactic":"lemma sum_cons [AddCommMonoid M] (n : ℕ) (σ : Fin n →₀ M) (i : M) :\n (sum (cons i σ) fun _ e ↦ e) = i + sum σ (fun _ e ↦ e) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.690_0.MEVUz78Vsm81fPx","decl":"lemma sum_cons [AddCommMonoid M] (n : ℕ) (σ : Fin n →₀ M) (i : M) :\n (sum (cons i σ) fun _ e ↦ e) = i + sum σ (fun _ e ↦ e) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni✝ : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\nn : ℕ\nσ : Fin n →₀ M\ni : M\n⊢ ∑ i_1 : Fin (n + 1), (cons i σ) i_1 = i + sum σ fun x e => e","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n rw [not_mem_support_iff.mp hi]\n rw [single_zero]\n#align finsupp.indicator_eq_sum_single Finsupp.indicator_eq_sum_attach_single\n\nlemma indicator_eq_sum_single [AddCommMonoid M] (s : Finset α) (f : α → M) :\n indicator s (fun x _ ↦ f x) = ∑ x in s, single x (f x) :=\n (indicator_eq_sum_attach_single _).trans <| sum_attach (f := fun x ↦ single x (f x))\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n rw [prod_of_support_subset _ (support_indicator_subset _ _) h h_zero]\n rw [← prod_attach]\n refine' Finset.prod_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n#align finsupp.prod_indicator_index Finsupp.prod_indicator_index_eq_prod_attach\n#align finsupp.sum_indicator_index Finsupp.sum_indicator_index_eq_sum_attach\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index [Zero M] [CommMonoid N]\n {s : Finset α} (f : α → M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s (fun x _ ↦ f x)).prod h = ∏ x in s, h x (f x) :=\n (prod_indicator_index_eq_prod_attach _ h_zero).trans <| prod_attach (f := fun x ↦ h x (f x))\n\nlemma sum_cons [AddCommMonoid M] (n : ℕ) (σ : Fin n →₀ M) (i : M) :\n (sum (cons i σ) fun _ e ↦ e) = i + sum σ (fun _ e ↦ e) := by\n rw [sum_fintype _ _ (fun _ => rfl)]\n ","nextTactic":"rw [sum_fintype _ _ (fun _ => rfl)]","declUpToTactic":"lemma sum_cons [AddCommMonoid M] (n : ℕ) (σ : Fin n →₀ M) (i : M) :\n (sum (cons i σ) fun _ e ↦ e) = i + sum σ (fun _ e ↦ e) := by\n rw [sum_fintype _ _ (fun _ => rfl)]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.690_0.MEVUz78Vsm81fPx","decl":"lemma sum_cons [AddCommMonoid M] (n : ℕ) (σ : Fin n →₀ M) (i : M) :\n (sum (cons i σ) fun _ e ↦ e) = i + sum σ (fun _ e ↦ e) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝³ : AddCommMonoid A\ninst✝² : AddCommMonoid B\ninst✝¹ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf : α → ι →₀ A\ni✝ : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝ : AddCommMonoid M\nn : ℕ\nσ : Fin n →₀ M\ni : M\n⊢ ∑ i_1 : Fin (n + 1), (cons i σ) i_1 = i + ∑ i : Fin n, σ i","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n rw [not_mem_support_iff.mp hi]\n rw [single_zero]\n#align finsupp.indicator_eq_sum_single Finsupp.indicator_eq_sum_attach_single\n\nlemma indicator_eq_sum_single [AddCommMonoid M] (s : Finset α) (f : α → M) :\n indicator s (fun x _ ↦ f x) = ∑ x in s, single x (f x) :=\n (indicator_eq_sum_attach_single _).trans <| sum_attach (f := fun x ↦ single x (f x))\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n rw [prod_of_support_subset _ (support_indicator_subset _ _) h h_zero]\n rw [← prod_attach]\n refine' Finset.prod_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n#align finsupp.prod_indicator_index Finsupp.prod_indicator_index_eq_prod_attach\n#align finsupp.sum_indicator_index Finsupp.sum_indicator_index_eq_sum_attach\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index [Zero M] [CommMonoid N]\n {s : Finset α} (f : α → M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s (fun x _ ↦ f x)).prod h = ∏ x in s, h x (f x) :=\n (prod_indicator_index_eq_prod_attach _ h_zero).trans <| prod_attach (f := fun x ↦ h x (f x))\n\nlemma sum_cons [AddCommMonoid M] (n : ℕ) (σ : Fin n →₀ M) (i : M) :\n (sum (cons i σ) fun _ e ↦ e) = i + sum σ (fun _ e ↦ e) := by\n rw [sum_fintype _ _ (fun _ => rfl)]\n rw [sum_fintype _ _ (fun _ => rfl)]\n ","nextTactic":"exact Fin.sum_cons i σ","declUpToTactic":"lemma sum_cons [AddCommMonoid M] (n : ℕ) (σ : Fin n →₀ M) (i : M) :\n (sum (cons i σ) fun _ e ↦ e) = i + sum σ (fun _ e ↦ e) := by\n rw [sum_fintype _ _ (fun _ => rfl)]\n rw [sum_fintype _ _ (fun _ => rfl)]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.690_0.MEVUz78Vsm81fPx","decl":"lemma sum_cons [AddCommMonoid M] (n : ℕ) (σ : Fin n →₀ M) (i : M) :\n (sum (cons i σ) fun _ e ↦ e) = i + sum σ (fun _ e ↦ e) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni✝ : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : AddCommMonoid N\nn : ℕ\nσ : Fin n →₀ M\ni : M\nf : Fin (n + 1) → M → N\nh : ∀ (x : Fin (n + 1)), f x 0 = 0\n⊢ sum (cons i σ) f = f 0 i + sum σ (Fin.tail f)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n rw [not_mem_support_iff.mp hi]\n rw [single_zero]\n#align finsupp.indicator_eq_sum_single Finsupp.indicator_eq_sum_attach_single\n\nlemma indicator_eq_sum_single [AddCommMonoid M] (s : Finset α) (f : α → M) :\n indicator s (fun x _ ↦ f x) = ∑ x in s, single x (f x) :=\n (indicator_eq_sum_attach_single _).trans <| sum_attach (f := fun x ↦ single x (f x))\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n rw [prod_of_support_subset _ (support_indicator_subset _ _) h h_zero]\n rw [← prod_attach]\n refine' Finset.prod_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n#align finsupp.prod_indicator_index Finsupp.prod_indicator_index_eq_prod_attach\n#align finsupp.sum_indicator_index Finsupp.sum_indicator_index_eq_sum_attach\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index [Zero M] [CommMonoid N]\n {s : Finset α} (f : α → M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s (fun x _ ↦ f x)).prod h = ∏ x in s, h x (f x) :=\n (prod_indicator_index_eq_prod_attach _ h_zero).trans <| prod_attach (f := fun x ↦ h x (f x))\n\nlemma sum_cons [AddCommMonoid M] (n : ℕ) (σ : Fin n →₀ M) (i : M) :\n (sum (cons i σ) fun _ e ↦ e) = i + sum σ (fun _ e ↦ e) := by\n rw [sum_fintype _ _ (fun _ => rfl)]\n rw [sum_fintype _ _ (fun _ => rfl)]\n exact Fin.sum_cons i σ\n\nlemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)\n (f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :\n (sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) := by\n ","nextTactic":"rw [sum_fintype _ _ (fun _ => by apply h), sum_fintype _ _ (fun _ => by apply h)]","declUpToTactic":"lemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)\n (f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :\n (sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) := by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.696_0.MEVUz78Vsm81fPx","decl":"lemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)\n (f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :\n (sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni✝ : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : AddCommMonoid N\nn : ℕ\nσ : Fin n →₀ M\ni : M\nf : Fin (n + 1) → M → N\nh : ∀ (x : Fin (n + 1)), f x 0 = 0\nx✝ : Fin (n + 1)\n⊢ f x✝ 0 = 0","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n rw [not_mem_support_iff.mp hi]\n rw [single_zero]\n#align finsupp.indicator_eq_sum_single Finsupp.indicator_eq_sum_attach_single\n\nlemma indicator_eq_sum_single [AddCommMonoid M] (s : Finset α) (f : α → M) :\n indicator s (fun x _ ↦ f x) = ∑ x in s, single x (f x) :=\n (indicator_eq_sum_attach_single _).trans <| sum_attach (f := fun x ↦ single x (f x))\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n rw [prod_of_support_subset _ (support_indicator_subset _ _) h h_zero]\n rw [← prod_attach]\n refine' Finset.prod_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n#align finsupp.prod_indicator_index Finsupp.prod_indicator_index_eq_prod_attach\n#align finsupp.sum_indicator_index Finsupp.sum_indicator_index_eq_sum_attach\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index [Zero M] [CommMonoid N]\n {s : Finset α} (f : α → M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s (fun x _ ↦ f x)).prod h = ∏ x in s, h x (f x) :=\n (prod_indicator_index_eq_prod_attach _ h_zero).trans <| prod_attach (f := fun x ↦ h x (f x))\n\nlemma sum_cons [AddCommMonoid M] (n : ℕ) (σ : Fin n →₀ M) (i : M) :\n (sum (cons i σ) fun _ e ↦ e) = i + sum σ (fun _ e ↦ e) := by\n rw [sum_fintype _ _ (fun _ => rfl)]\n rw [sum_fintype _ _ (fun _ => rfl)]\n exact Fin.sum_cons i σ\n\nlemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)\n (f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :\n (sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) := by\n rw [sum_fintype _ _ (fun _ => by ","nextTactic":"apply h","declUpToTactic":"lemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)\n (f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :\n (sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) := by\n rw [sum_fintype _ _ (fun _ => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.696_0.MEVUz78Vsm81fPx","decl":"lemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)\n (f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :\n (sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni✝ : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : AddCommMonoid N\nn : ℕ\nσ : Fin n →₀ M\ni : M\nf : Fin (n + 1) → M → N\nh : ∀ (x : Fin (n + 1)), f x 0 = 0\nx✝ : Fin n\n⊢ Fin.tail f x✝ 0 = 0","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n rw [not_mem_support_iff.mp hi]\n rw [single_zero]\n#align finsupp.indicator_eq_sum_single Finsupp.indicator_eq_sum_attach_single\n\nlemma indicator_eq_sum_single [AddCommMonoid M] (s : Finset α) (f : α → M) :\n indicator s (fun x _ ↦ f x) = ∑ x in s, single x (f x) :=\n (indicator_eq_sum_attach_single _).trans <| sum_attach (f := fun x ↦ single x (f x))\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n rw [prod_of_support_subset _ (support_indicator_subset _ _) h h_zero]\n rw [← prod_attach]\n refine' Finset.prod_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n#align finsupp.prod_indicator_index Finsupp.prod_indicator_index_eq_prod_attach\n#align finsupp.sum_indicator_index Finsupp.sum_indicator_index_eq_sum_attach\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index [Zero M] [CommMonoid N]\n {s : Finset α} (f : α → M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s (fun x _ ↦ f x)).prod h = ∏ x in s, h x (f x) :=\n (prod_indicator_index_eq_prod_attach _ h_zero).trans <| prod_attach (f := fun x ↦ h x (f x))\n\nlemma sum_cons [AddCommMonoid M] (n : ℕ) (σ : Fin n →₀ M) (i : M) :\n (sum (cons i σ) fun _ e ↦ e) = i + sum σ (fun _ e ↦ e) := by\n rw [sum_fintype _ _ (fun _ => rfl)]\n rw [sum_fintype _ _ (fun _ => rfl)]\n exact Fin.sum_cons i σ\n\nlemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)\n (f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :\n (sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) := by\n rw [sum_fintype _ _ (fun _ => by apply h), sum_fintype _ _ (fun _ => by ","nextTactic":"apply h","declUpToTactic":"lemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)\n (f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :\n (sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) := by\n rw [sum_fintype _ _ (fun _ => by apply h), sum_fintype _ _ (fun _ => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.696_0.MEVUz78Vsm81fPx","decl":"lemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)\n (f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :\n (sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni✝ : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : AddCommMonoid N\nn : ℕ\nσ : Fin n →₀ M\ni : M\nf : Fin (n + 1) → M → N\nh : ∀ (x : Fin (n + 1)), f x 0 = 0\n⊢ ∑ i_1 : Fin (n + 1), f i_1 ((cons i σ) i_1) = f 0 i + ∑ i : Fin n, Fin.tail f i (σ i)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n rw [not_mem_support_iff.mp hi]\n rw [single_zero]\n#align finsupp.indicator_eq_sum_single Finsupp.indicator_eq_sum_attach_single\n\nlemma indicator_eq_sum_single [AddCommMonoid M] (s : Finset α) (f : α → M) :\n indicator s (fun x _ ↦ f x) = ∑ x in s, single x (f x) :=\n (indicator_eq_sum_attach_single _).trans <| sum_attach (f := fun x ↦ single x (f x))\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n rw [prod_of_support_subset _ (support_indicator_subset _ _) h h_zero]\n rw [← prod_attach]\n refine' Finset.prod_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n#align finsupp.prod_indicator_index Finsupp.prod_indicator_index_eq_prod_attach\n#align finsupp.sum_indicator_index Finsupp.sum_indicator_index_eq_sum_attach\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index [Zero M] [CommMonoid N]\n {s : Finset α} (f : α → M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s (fun x _ ↦ f x)).prod h = ∏ x in s, h x (f x) :=\n (prod_indicator_index_eq_prod_attach _ h_zero).trans <| prod_attach (f := fun x ↦ h x (f x))\n\nlemma sum_cons [AddCommMonoid M] (n : ℕ) (σ : Fin n →₀ M) (i : M) :\n (sum (cons i σ) fun _ e ↦ e) = i + sum σ (fun _ e ↦ e) := by\n rw [sum_fintype _ _ (fun _ => rfl)]\n rw [sum_fintype _ _ (fun _ => rfl)]\n exact Fin.sum_cons i σ\n\nlemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)\n (f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :\n (sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) := by\n rw [sum_fintype _ _ (fun _ => by apply h), sum_fintype _ _ (fun _ => by apply h)]\n ","nextTactic":"simp_rw [Fin.sum_univ_succ, cons_zero, cons_succ]","declUpToTactic":"lemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)\n (f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :\n (sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) := by\n rw [sum_fintype _ _ (fun _ => by apply h), sum_fintype _ _ (fun _ => by apply h)]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.696_0.MEVUz78Vsm81fPx","decl":"lemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)\n (f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :\n (sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni✝ : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : AddCommMonoid M\ninst✝ : AddCommMonoid N\nn : ℕ\nσ : Fin n →₀ M\ni : M\nf : Fin (n + 1) → M → N\nh : ∀ (x : Fin (n + 1)), f x 0 = 0\n⊢ f 0 i + ∑ x : Fin n, f (Fin.succ x) (σ x) = f 0 i + ∑ i : Fin n, Fin.tail f i (σ i)","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n rw [not_mem_support_iff.mp hi]\n rw [single_zero]\n#align finsupp.indicator_eq_sum_single Finsupp.indicator_eq_sum_attach_single\n\nlemma indicator_eq_sum_single [AddCommMonoid M] (s : Finset α) (f : α → M) :\n indicator s (fun x _ ↦ f x) = ∑ x in s, single x (f x) :=\n (indicator_eq_sum_attach_single _).trans <| sum_attach (f := fun x ↦ single x (f x))\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n rw [prod_of_support_subset _ (support_indicator_subset _ _) h h_zero]\n rw [← prod_attach]\n refine' Finset.prod_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n#align finsupp.prod_indicator_index Finsupp.prod_indicator_index_eq_prod_attach\n#align finsupp.sum_indicator_index Finsupp.sum_indicator_index_eq_sum_attach\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index [Zero M] [CommMonoid N]\n {s : Finset α} (f : α → M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s (fun x _ ↦ f x)).prod h = ∏ x in s, h x (f x) :=\n (prod_indicator_index_eq_prod_attach _ h_zero).trans <| prod_attach (f := fun x ↦ h x (f x))\n\nlemma sum_cons [AddCommMonoid M] (n : ℕ) (σ : Fin n →₀ M) (i : M) :\n (sum (cons i σ) fun _ e ↦ e) = i + sum σ (fun _ e ↦ e) := by\n rw [sum_fintype _ _ (fun _ => rfl)]\n rw [sum_fintype _ _ (fun _ => rfl)]\n exact Fin.sum_cons i σ\n\nlemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)\n (f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :\n (sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) := by\n rw [sum_fintype _ _ (fun _ => by apply h), sum_fintype _ _ (fun _ => by apply h)]\n simp_rw [Fin.sum_univ_succ, cons_zero, cons_succ]\n ","nextTactic":"congr","declUpToTactic":"lemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)\n (f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :\n (sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) := by\n rw [sum_fintype _ _ (fun _ => by apply h), sum_fintype _ _ (fun _ => by apply h)]\n simp_rw [Fin.sum_univ_succ, cons_zero, cons_succ]\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.696_0.MEVUz78Vsm81fPx","decl":"lemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)\n (f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :\n (sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝² : AddCommMonoid A\ninst✝¹ : AddCommMonoid B\ninst✝ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\na : α\ns : Finset α\nhas : a ∉ s\nih : sum (∑ x in s, f x) t = ∑ x in s, sum (f x) t\n⊢ sum (∑ x in insert a s, f x) t = ∑ x in insert a s, sum (f x) t","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n rw [not_mem_support_iff.mp hi]\n rw [single_zero]\n#align finsupp.indicator_eq_sum_single Finsupp.indicator_eq_sum_attach_single\n\nlemma indicator_eq_sum_single [AddCommMonoid M] (s : Finset α) (f : α → M) :\n indicator s (fun x _ ↦ f x) = ∑ x in s, single x (f x) :=\n (indicator_eq_sum_attach_single _).trans <| sum_attach (f := fun x ↦ single x (f x))\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n rw [prod_of_support_subset _ (support_indicator_subset _ _) h h_zero]\n rw [← prod_attach]\n refine' Finset.prod_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n#align finsupp.prod_indicator_index Finsupp.prod_indicator_index_eq_prod_attach\n#align finsupp.sum_indicator_index Finsupp.sum_indicator_index_eq_sum_attach\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index [Zero M] [CommMonoid N]\n {s : Finset α} (f : α → M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s (fun x _ ↦ f x)).prod h = ∏ x in s, h x (f x) :=\n (prod_indicator_index_eq_prod_attach _ h_zero).trans <| prod_attach (f := fun x ↦ h x (f x))\n\nlemma sum_cons [AddCommMonoid M] (n : ℕ) (σ : Fin n →₀ M) (i : M) :\n (sum (cons i σ) fun _ e ↦ e) = i + sum σ (fun _ e ↦ e) := by\n rw [sum_fintype _ _ (fun _ => rfl)]\n rw [sum_fintype _ _ (fun _ => rfl)]\n exact Fin.sum_cons i σ\n\nlemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)\n (f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :\n (sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) := by\n rw [sum_fintype _ _ (fun _ => by apply h), sum_fintype _ _ (fun _ => by apply h)]\n simp_rw [Fin.sum_univ_succ, cons_zero, cons_succ]\n congr\n\nend Finsupp\n\ntheorem Finset.sum_apply' : (∑ k in s, f k) i = ∑ k in s, f k i :=\n map_sum (Finsupp.applyAddHom i) f s\n#align finset.sum_apply' Finset.sum_apply'\n\ntheorem Finsupp.sum_apply' : g.sum k x = g.sum fun i b => k i b x :=\n Finset.sum_apply _ _ _\n#align finsupp.sum_apply' Finsupp.sum_apply'\n\nsection\n\nopen Classical\n\ntheorem Finsupp.sum_sum_index' : (∑ x in s, f x).sum t = ∑ x in s, (f x).sum t :=\n Finset.induction_on s rfl fun a s has ih => by\n ","nextTactic":"simp_rw [Finset.sum_insert has, Finsupp.sum_add_index' h0 h1, ih]","declUpToTactic":"theorem Finsupp.sum_sum_index' : (∑ x in s, f x).sum t = ∑ x in s, (f x).sum t :=\n Finset.induction_on s rfl fun a s has ih => by\n ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.717_0.MEVUz78Vsm81fPx","decl":"theorem Finsupp.sum_sum_index' : (∑ x in s, f x).sum t = ∑ x in s, (f x).sum t "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : NonUnitalNonAssocSemiring R\ninst✝ : NonUnitalNonAssocSemiring S\nb : S\ns : α →₀ R\nf : α → R → S\n⊢ sum s f * b = sum s fun a c => f a c * b","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α ��₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n rw [not_mem_support_iff.mp hi]\n rw [single_zero]\n#align finsupp.indicator_eq_sum_single Finsupp.indicator_eq_sum_attach_single\n\nlemma indicator_eq_sum_single [AddCommMonoid M] (s : Finset α) (f : α → M) :\n indicator s (fun x _ ↦ f x) = ∑ x in s, single x (f x) :=\n (indicator_eq_sum_attach_single _).trans <| sum_attach (f := fun x ↦ single x (f x))\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n rw [prod_of_support_subset _ (support_indicator_subset _ _) h h_zero]\n rw [← prod_attach]\n refine' Finset.prod_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n#align finsupp.prod_indicator_index Finsupp.prod_indicator_index_eq_prod_attach\n#align finsupp.sum_indicator_index Finsupp.sum_indicator_index_eq_sum_attach\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index [Zero M] [CommMonoid N]\n {s : Finset α} (f : α → M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s (fun x _ ↦ f x)).prod h = ∏ x in s, h x (f x) :=\n (prod_indicator_index_eq_prod_attach _ h_zero).trans <| prod_attach (f := fun x ↦ h x (f x))\n\nlemma sum_cons [AddCommMonoid M] (n : ℕ) (σ : Fin n →₀ M) (i : M) :\n (sum (cons i σ) fun _ e ↦ e) = i + sum σ (fun _ e ↦ e) := by\n rw [sum_fintype _ _ (fun _ => rfl)]\n rw [sum_fintype _ _ (fun _ => rfl)]\n exact Fin.sum_cons i σ\n\nlemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)\n (f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :\n (sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) := by\n rw [sum_fintype _ _ (fun _ => by apply h), sum_fintype _ _ (fun _ => by apply h)]\n simp_rw [Fin.sum_univ_succ, cons_zero, cons_succ]\n congr\n\nend Finsupp\n\ntheorem Finset.sum_apply' : (∑ k in s, f k) i = ∑ k in s, f k i :=\n map_sum (Finsupp.applyAddHom i) f s\n#align finset.sum_apply' Finset.sum_apply'\n\ntheorem Finsupp.sum_apply' : g.sum k x = g.sum fun i b => k i b x :=\n Finset.sum_apply _ _ _\n#align finsupp.sum_apply' Finsupp.sum_apply'\n\nsection\n\nopen Classical\n\ntheorem Finsupp.sum_sum_index' : (∑ x in s, f x).sum t = ∑ x in s, (f x).sum t :=\n Finset.induction_on s rfl fun a s has ih => by\n simp_rw [Finset.sum_insert has, Finsupp.sum_add_index' h0 h1, ih]\n#align finsupp.sum_sum_index' Finsupp.sum_sum_index'\n\nend\n\nsection\n\nvariable [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S]\n\ntheorem Finsupp.sum_mul (b : S) (s : α →₀ R) {f : α → R → S} :\n s.sum f * b = s.sum fun a c => f a c * b := by ","nextTactic":"simp only [Finsupp.sum, Finset.sum_mul]","declUpToTactic":"theorem Finsupp.sum_mul (b : S) (s : α →₀ R) {f : α → R → S} :\n s.sum f * b = s.sum fun a c => f a c * b := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.728_0.MEVUz78Vsm81fPx","decl":"theorem Finsupp.sum_mul (b : S) (s : α →₀ R) {f : α → R → S} :\n s.sum f * b = s.sum fun a c => f a c * b "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝⁴ : AddCommMonoid A\ninst✝³ : AddCommMonoid B\ninst✝² : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns✝ : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\ninst✝¹ : NonUnitalNonAssocSemiring R\ninst✝ : NonUnitalNonAssocSemiring S\nb : S\ns : α →₀ R\nf : α → R → S\n⊢ b * sum s f = sum s fun a c => b * f a c","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n rw [not_mem_support_iff.mp hi]\n rw [single_zero]\n#align finsupp.indicator_eq_sum_single Finsupp.indicator_eq_sum_attach_single\n\nlemma indicator_eq_sum_single [AddCommMonoid M] (s : Finset α) (f : α → M) :\n indicator s (fun x _ ↦ f x) = ∑ x in s, single x (f x) :=\n (indicator_eq_sum_attach_single _).trans <| sum_attach (f := fun x ↦ single x (f x))\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n rw [prod_of_support_subset _ (support_indicator_subset _ _) h h_zero]\n rw [← prod_attach]\n refine' Finset.prod_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n#align finsupp.prod_indicator_index Finsupp.prod_indicator_index_eq_prod_attach\n#align finsupp.sum_indicator_index Finsupp.sum_indicator_index_eq_sum_attach\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index [Zero M] [CommMonoid N]\n {s : Finset α} (f : α → M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s (fun x _ ↦ f x)).prod h = ∏ x in s, h x (f x) :=\n (prod_indicator_index_eq_prod_attach _ h_zero).trans <| prod_attach (f := fun x ↦ h x (f x))\n\nlemma sum_cons [AddCommMonoid M] (n : ℕ) (σ : Fin n →₀ M) (i : M) :\n (sum (cons i σ) fun _ e ↦ e) = i + sum σ (fun _ e ↦ e) := by\n rw [sum_fintype _ _ (fun _ => rfl)]\n rw [sum_fintype _ _ (fun _ => rfl)]\n exact Fin.sum_cons i σ\n\nlemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)\n (f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :\n (sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) := by\n rw [sum_fintype _ _ (fun _ => by apply h), sum_fintype _ _ (fun _ => by apply h)]\n simp_rw [Fin.sum_univ_succ, cons_zero, cons_succ]\n congr\n\nend Finsupp\n\ntheorem Finset.sum_apply' : (∑ k in s, f k) i = ∑ k in s, f k i :=\n map_sum (Finsupp.applyAddHom i) f s\n#align finset.sum_apply' Finset.sum_apply'\n\ntheorem Finsupp.sum_apply' : g.sum k x = g.sum fun i b => k i b x :=\n Finset.sum_apply _ _ _\n#align finsupp.sum_apply' Finsupp.sum_apply'\n\nsection\n\nopen Classical\n\ntheorem Finsupp.sum_sum_index' : (∑ x in s, f x).sum t = ∑ x in s, (f x).sum t :=\n Finset.induction_on s rfl fun a s has ih => by\n simp_rw [Finset.sum_insert has, Finsupp.sum_add_index' h0 h1, ih]\n#align finsupp.sum_sum_index' Finsupp.sum_sum_index'\n\nend\n\nsection\n\nvariable [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S]\n\ntheorem Finsupp.sum_mul (b : S) (s : α →₀ R) {f : α → R → S} :\n s.sum f * b = s.sum fun a c => f a c * b := by simp only [Finsupp.sum, Finset.sum_mul]\n#align finsupp.sum_mul Finsupp.sum_mul\n\ntheorem Finsupp.mul_sum (b : S) (s : α →₀ R) {f : α → R → S} :\n b * s.sum f = s.sum fun a c => b * f a c := by ","nextTactic":"simp only [Finsupp.sum, Finset.mul_sum]","declUpToTactic":"theorem Finsupp.mul_sum (b : S) (s : α →₀ R) {f : α → R → S} :\n b * s.sum f = s.sum fun a c => b * f a c := by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.732_0.MEVUz78Vsm81fPx","decl":"theorem Finsupp.mul_sum (b : S) (s : α →₀ R) {f : α → R → S} :\n b * s.sum f = s.sum fun a c => b * f a c "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝² : AddCommMonoid A\ninst✝¹ : AddCommMonoid B\ninst✝ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH✝ : Type u_13\nR : Type u_14\nS : Type u_15\nf : ℕ →₀ ℕ\nhf : 0 ∉ f.support\na : ℕ\nha : a ∈ f.support\nH : a = 0\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n rw [not_mem_support_iff.mp hi]\n rw [single_zero]\n#align finsupp.indicator_eq_sum_single Finsupp.indicator_eq_sum_attach_single\n\nlemma indicator_eq_sum_single [AddCommMonoid M] (s : Finset α) (f : α → M) :\n indicator s (fun x _ ↦ f x) = ∑ x in s, single x (f x) :=\n (indicator_eq_sum_attach_single _).trans <| sum_attach (f := fun x ↦ single x (f x))\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n rw [prod_of_support_subset _ (support_indicator_subset _ _) h h_zero]\n rw [← prod_attach]\n refine' Finset.prod_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n#align finsupp.prod_indicator_index Finsupp.prod_indicator_index_eq_prod_attach\n#align finsupp.sum_indicator_index Finsupp.sum_indicator_index_eq_sum_attach\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index [Zero M] [CommMonoid N]\n {s : Finset α} (f : α → M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s (fun x _ ↦ f x)).prod h = ∏ x in s, h x (f x) :=\n (prod_indicator_index_eq_prod_attach _ h_zero).trans <| prod_attach (f := fun x ↦ h x (f x))\n\nlemma sum_cons [AddCommMonoid M] (n : ℕ) (σ : Fin n →₀ M) (i : M) :\n (sum (cons i σ) fun _ e ↦ e) = i + sum σ (fun _ e ↦ e) := by\n rw [sum_fintype _ _ (fun _ => rfl)]\n rw [sum_fintype _ _ (fun _ => rfl)]\n exact Fin.sum_cons i σ\n\nlemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)\n (f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :\n (sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) := by\n rw [sum_fintype _ _ (fun _ => by apply h), sum_fintype _ _ (fun _ => by apply h)]\n simp_rw [Fin.sum_univ_succ, cons_zero, cons_succ]\n congr\n\nend Finsupp\n\ntheorem Finset.sum_apply' : (∑ k in s, f k) i = ∑ k in s, f k i :=\n map_sum (Finsupp.applyAddHom i) f s\n#align finset.sum_apply' Finset.sum_apply'\n\ntheorem Finsupp.sum_apply' : g.sum k x = g.sum fun i b => k i b x :=\n Finset.sum_apply _ _ _\n#align finsupp.sum_apply' Finsupp.sum_apply'\n\nsection\n\nopen Classical\n\ntheorem Finsupp.sum_sum_index' : (∑ x in s, f x).sum t = ∑ x in s, (f x).sum t :=\n Finset.induction_on s rfl fun a s has ih => by\n simp_rw [Finset.sum_insert has, Finsupp.sum_add_index' h0 h1, ih]\n#align finsupp.sum_sum_index' Finsupp.sum_sum_index'\n\nend\n\nsection\n\nvariable [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S]\n\ntheorem Finsupp.sum_mul (b : S) (s : α →₀ R) {f : α → R → S} :\n s.sum f * b = s.sum fun a c => f a c * b := by simp only [Finsupp.sum, Finset.sum_mul]\n#align finsupp.sum_mul Finsupp.sum_mul\n\ntheorem Finsupp.mul_sum (b : S) (s : α →₀ R) {f : α → R → S} :\n b * s.sum f = s.sum fun a c => b * f a c := by simp only [Finsupp.sum, Finset.mul_sum]\n#align finsupp.mul_sum Finsupp.mul_sum\n\nend\n\nnamespace Nat\n\n-- Porting note: Needed to replace pow with (· ^ ·)\n/-- If `0 : ℕ` is not in the support of `f : ℕ →₀ ℕ` then `0 < ∏ x in f.support, x ^ (f x)`. -/\ntheorem prod_pow_pos_of_zero_not_mem_support {f : ℕ →₀ ℕ} (hf : 0 ∉ f.support) :\n 0 < f.prod (· ^ ·) :=\n Finset.prod_pos fun a ha => pos_iff_ne_zero.mpr (pow_ne_zero _ fun H => by ","nextTactic":"subst H","declUpToTactic":"/-- If `0 : ℕ` is not in the support of `f : ℕ →₀ ℕ` then `0 < ∏ x in f.support, x ^ (f x)`. -/\ntheorem prod_pow_pos_of_zero_not_mem_support {f : ℕ →₀ ℕ} (hf : 0 ∉ f.support) :\n 0 < f.prod (· ^ ·) :=\n Finset.prod_pos fun a ha => pos_iff_ne_zero.mpr (pow_ne_zero _ fun H => by ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.741_0.MEVUz78Vsm81fPx","decl":"/-- If `0 : ℕ` is not in the support of `f : ℕ →₀ ℕ` then `0 < ∏ x in f.support, x ^ (f x)`. -/\ntheorem prod_pow_pos_of_zero_not_mem_support {f : ℕ →₀ ℕ} (hf : 0 ∉ f.support) :\n 0 < f.prod (· ^ ·) "} -{"state":"α : Type u_1\nι : Type u_2\nγ : Type u_3\nA : Type u_4\nB : Type u_5\nC : Type u_6\ninst✝² : AddCommMonoid A\ninst✝¹ : AddCommMonoid B\ninst✝ : AddCommMonoid C\nt : ι → A → C\nh0 : ∀ (i : ι), t i 0 = 0\nh1 : ∀ (i : ι) (x y : A), t i (x + y) = t i x + t i y\ns : Finset α\nf✝ : α → ι →₀ A\ni : ι\ng : ι →₀ A\nk : ι → A → γ → B\nx : γ\nβ : Type u_7\nM : Type u_8\nM' : Type u_9\nN : Type u_10\nP : Type u_11\nG : Type u_12\nH : Type u_13\nR : Type u_14\nS : Type u_15\nf : ℕ →₀ ℕ\nhf : 0 ∉ f.support\nha : 0 ∈ f.support\n⊢ False","srcUpToTactic":"/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kenny Lau\n-/\nimport Mathlib.Data.Finsupp.Indicator\nimport Mathlib.Algebra.BigOperators.Pi\nimport Mathlib.Algebra.BigOperators.Ring\nimport Mathlib.Algebra.BigOperators.Order\nimport Mathlib.Algebra.BigOperators.Fin\nimport Mathlib.Data.Finsupp.Fin\nimport Mathlib.GroupTheory.Submonoid.Membership\n\n#align_import algebra.big_operators.finsupp from \"leanprover-community/mathlib\"@\"842328d9df7e96fd90fc424e115679c15fb23a71\"\n\n/-!\n# Big operators for finsupps\n\nThis file contains theorems relevant to big operators in finitely supported functions.\n-/\n\n\nnoncomputable section\n\nopen Finset Function\n\nopen BigOperators\n\nvariable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]\n\nvariable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)\n\nvariable {s : Finset α} {f : α → ι →₀ A} (i : ι)\n\nvariable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)\n\nvariable {β M M' N P G H R S : Type*}\n\nnamespace Finsupp\n\n/-!\n### Declarations about `sum` and `prod`\n\nIn most of this section, the domain `β` is assumed to be an `AddMonoid`.\n-/\n\n\nsection SumProd\n\n/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/\n@[to_additive \"`sum f g` is the sum of `g a (f a)` over the support of `f`. \"]\ndef prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=\n ∏ a in f.support, g a (f a)\n#align finsupp.prod Finsupp.prod\n#align finsupp.sum Finsupp.sum\n\nvariable [Zero M] [Zero M'] [CommMonoid N]\n\n@[to_additive]\ntheorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)\n (h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x in s, g x (f x) := by\n refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)\n exact not_mem_support_iff.1 hx\n#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset\n#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset\n\n@[to_additive]\ntheorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :\n f.prod g = ∏ i, g i (f i) :=\n f.prod_of_support_subset (subset_univ _) g fun x _ => h x\n#align finsupp.prod_fintype Finsupp.prod_fintype\n#align finsupp.sum_fintype Finsupp.sum_fintype\n\n@[to_additive (attr := simp)]\ntheorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :\n (single a b).prod h = h a b :=\n calc\n (single a b).prod h = ∏ x in {a}, h x (single a b x) :=\n prod_of_support_subset _ support_single_subset h fun x hx =>\n (mem_singleton.1 hx).symm ▸ h_zero\n _ = h a b := by simp\n#align finsupp.prod_single_index Finsupp.prod_single_index\n#align finsupp.sum_single_index Finsupp.sum_single_index\n\n@[to_additive]\ntheorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}\n (h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=\n Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]\n#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index\n#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index\n\n@[to_additive (attr := simp)]\ntheorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=\n rfl\n#align finsupp.prod_zero_index Finsupp.prod_zero_index\n#align finsupp.sum_zero_index Finsupp.sum_zero_index\n\n@[to_additive]\ntheorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :\n (f.prod fun x v => g.prod fun x' v' => h x v x' v') =\n g.prod fun x' v' => f.prod fun x v => h x v x' v' :=\n Finset.prod_comm\n#align finsupp.prod_comm Finsupp.prod_comm\n#align finsupp.sum_comm Finsupp.sum_comm\n\n@[to_additive (attr := simp)]\ntheorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq]\n#align finsupp.prod_ite_eq Finsupp.prod_ite_eq\n#align finsupp.sum_ite_eq Finsupp.sum_ite_eq\n\n/- Porting note: simpnf linter, added aux lemma below\nLeft-hand side simplifies from\n Finsupp.sum f fun x v => if a = x then v else 0\nto\n if ↑f a = 0 then 0 else ↑f a\n-/\n-- @[simp]\ntheorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (a = x) v 0) = f a := by\n classical\n convert f.sum_ite_eq a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq\n\n-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]\n@[simp]\ntheorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (if a ∈ f.support then f a else 0) = f a := by\n simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]\n exact fun h ↦ h.symm\n\n/-- A restatement of `prod_ite_eq` with the equality test reversed. -/\n@[to_additive (attr := simp) \"A restatement of `sum_ite_eq` with the equality test reversed.\"]\ntheorem prod_ite_eq' [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :\n (f.prod fun x v => ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by\n dsimp [Finsupp.prod]\n rw [f.support.prod_ite_eq']\n#align finsupp.prod_ite_eq' Finsupp.prod_ite_eq'\n#align finsupp.sum_ite_eq' Finsupp.sum_ite_eq'\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem sum_ite_self_eq' [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :\n (f.sum fun x v => ite (x = a) v 0) = f a := by\n classical\n convert f.sum_ite_eq' a fun _ => id\n simp [ite_eq_right_iff.2 Eq.symm]\n#align finsupp.sum_ite_self_eq' Finsupp.sum_ite_self_eq'\n\n@[simp]\ntheorem prod_pow [Fintype α] (f : α →₀ ℕ) (g : α → N) :\n (f.prod fun a b => g a ^ b) = ∏ a, g a ^ f a :=\n f.prod_fintype _ fun _ ↦ pow_zero _\n#align finsupp.prod_pow Finsupp.prod_pow\n\n/-- If `g` maps a second argument of 0 to 1, then multiplying it over the\nresult of `onFinset` is the same as multiplying it over the original `Finset`. -/\n@[to_additive\n \"If `g` maps a second argument of 0 to 0, summing it over the\n result of `onFinset` is the same as summing it over the original `Finset`.\"]\ntheorem onFinset_prod {s : Finset α} {f : α → M} {g : α → M → N} (hf : ∀ a, f a ≠ 0 → a ∈ s)\n (hg : ∀ a, g a 0 = 1) : (onFinset s f hf).prod g = ∏ a in s, g a (f a) :=\n Finset.prod_subset support_onFinset_subset <| by simp (config := { contextual := true }) [*]\n#align finsupp.on_finset_prod Finsupp.onFinset_prod\n#align finsupp.on_finset_sum Finsupp.onFinset_sum\n\n/-- Taking a product over `f : α →₀ M` is the same as multiplying the value on a single element\n`y ∈ f.support` by the product over `erase y f`. -/\n@[to_additive\n \" Taking a sum over over `f : α →₀ M` is the same as adding the value on a\n single element `y ∈ f.support` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase (f : α →₀ M) (y : α) (g : α → M → N) (hyf : y ∈ f.support) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n rw [Finsupp.prod, Finsupp.prod, ← Finset.mul_prod_erase _ _ hyf, Finsupp.support_erase,\n Finset.prod_congr rfl]\n intro h hx\n rw [Finsupp.erase_ne (ne_of_mem_erase hx)]\n#align finsupp.mul_prod_erase Finsupp.mul_prod_erase\n#align finsupp.add_sum_erase Finsupp.add_sum_erase\n\n/-- Generalization of `Finsupp.mul_prod_erase`: if `g` maps a second argument of 0 to 1,\nthen its product over `f : α →₀ M` is the same as multiplying the value on any element\n`y : α` by the product over `erase y f`. -/\n@[to_additive\n \" Generalization of `Finsupp.add_sum_erase`: if `g` maps a second argument of 0\n to 0, then its sum over `f : α →₀ M` is the same as adding the value on any element\n `y : α` to the sum over `erase y f`. \"]\ntheorem mul_prod_erase' (f : α →₀ M) (y : α) (g : α → M → N) (hg : ∀ i : α, g i 0 = 1) :\n g y (f y) * (erase y f).prod g = f.prod g := by\n classical\n by_cases hyf : y ∈ f.support\n · exact Finsupp.mul_prod_erase f y g hyf\n · rw [not_mem_support_iff.mp hyf, hg y, erase_of_not_mem_support hyf, one_mul]\n#align finsupp.mul_prod_erase' Finsupp.mul_prod_erase'\n#align finsupp.add_sum_erase' Finsupp.add_sum_erase'\n\n@[to_additive]\ntheorem _root_.SubmonoidClass.finsupp_prod_mem {S : Type*} [SetLike S N] [SubmonoidClass S N]\n (s : S) (f : α →₀ M) (g : α → M → N) (h : ∀ c, f c ≠ 0 → g c (f c) ∈ s) : f.prod g ∈ s :=\n prod_mem fun _i hi => h _ (Finsupp.mem_support_iff.mp hi)\n#align submonoid_class.finsupp_prod_mem SubmonoidClass.finsupp_prod_mem\n#align add_submonoid_class.finsupp_sum_mem AddSubmonoidClass.finsupp_sum_mem\n\n@[to_additive]\ntheorem prod_congr {f : α →₀ M} {g1 g2 : α → M → N} (h : ∀ x ∈ f.support, g1 x (f x) = g2 x (f x)) :\n f.prod g1 = f.prod g2 :=\n Finset.prod_congr rfl h\n#align finsupp.prod_congr Finsupp.prod_congr\n#align finsupp.sum_congr Finsupp.sum_congr\n\n@[to_additive]\ntheorem prod_eq_single {f : α →₀ M} (a : α) {g : α → M → N}\n (h₀ : ∀ b, f b ≠ 0 → b ≠ a → g b (f b) = 1) (h₁ : f a = 0 → g a 0 = 1) :\n f.prod g = g a (f a) := by\n refine Finset.prod_eq_single a (fun b hb₁ hb₂ => ?_) (fun h => ?_)\n · exact h₀ b (mem_support_iff.mp hb₁) hb₂\n · simp only [not_mem_support_iff] at h\n rw [h]\n exact h₁ h\n\nend SumProd\n\nsection CommMonoidWithZero\nvariable [Zero α] [CommMonoidWithZero β] [Nontrivial β] [NoZeroDivisors β]\n {f : ι →₀ α} (a : α) {g : ι → α → β}\n\n@[simp]\nlemma prod_eq_zero_iff : f.prod g = 0 ↔ ∃ i ∈ f.support, g i (f i) = 0 := Finset.prod_eq_zero_iff\nlemma prod_ne_zero_iff : f.prod g ≠ 0 ↔ ∀ i ∈ f.support, g i (f i) ≠ 0 := Finset.prod_ne_zero_iff\n\nend CommMonoidWithZero\nend Finsupp\n\n@[to_additive]\ntheorem map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] {H : Type*} [MonoidHomClass H N P]\n (h : H) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_prod h _ _\n#align map_finsupp_prod map_finsupp_prod\n#align map_finsupp_sum map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MulEquiv.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N ≃* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align mul_equiv.map_finsupp_prod MulEquiv.map_finsupp_prod\n#align add_equiv.map_finsupp_sum AddEquiv.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[to_additive (attr := deprecated)\n \"Deprecated, use `_root_.map_finsupp_sum` instead.\"]\nprotected theorem MonoidHom.map_finsupp_prod [Zero M] [CommMonoid N] [CommMonoid P] (h : N →* P)\n (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align monoid_hom.map_finsupp_prod MonoidHom.map_finsupp_prod\n#align add_monoid_hom.map_finsupp_sum AddMonoidHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_sum` instead. -/\n@[deprecated map_finsupp_sum]\nprotected theorem RingHom.map_finsupp_sum [Zero M] [Semiring R] [Semiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum fun a b => h (g a b) :=\n map_finsupp_sum h f g\n#align ring_hom.map_finsupp_sum RingHom.map_finsupp_sum\n\n/-- Deprecated, use `_root_.map_finsupp_prod` instead. -/\n@[deprecated map_finsupp_prod]\nprotected theorem RingHom.map_finsupp_prod [Zero M] [CommSemiring R] [CommSemiring S] (h : R →+* S)\n (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod fun a b => h (g a b) :=\n map_finsupp_prod h f g\n#align ring_hom.map_finsupp_prod RingHom.map_finsupp_prod\n\n-- Porting note: inserted ⇑ on the rhs\n@[to_additive]\ntheorem MonoidHom.coe_finsupp_prod [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) : ⇑(f.prod g) = f.prod fun i fi => ⇑(g i fi) :=\n MonoidHom.coe_finset_prod _ _\n#align monoid_hom.coe_finsupp_prod MonoidHom.coe_finsupp_prod\n#align add_monoid_hom.coe_finsupp_sum AddMonoidHom.coe_finsupp_sum\n\n@[to_additive (attr := simp)]\ntheorem MonoidHom.finsupp_prod_apply [Zero β] [Monoid N] [CommMonoid P] (f : α →₀ β)\n (g : α → β → N →* P) (x : N) : f.prod g x = f.prod fun i fi => g i fi x :=\n MonoidHom.finset_prod_apply _ _ _\n#align monoid_hom.finsupp_prod_apply MonoidHom.finsupp_prod_apply\n#align add_monoid_hom.finsupp_sum_apply AddMonoidHom.finsupp_sum_apply\n\nnamespace Finsupp\n\ntheorem single_multiset_sum [AddCommMonoid M] (s : Multiset M) (a : α) :\n single a s.sum = (s.map (single a)).sum :=\n Multiset.induction_on s (single_zero _) fun a s ih => by\n rw [Multiset.sum_cons]\n rw [single_add]\n rw [ih]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n#align finsupp.single_multiset_sum Finsupp.single_multiset_sum\n\ntheorem single_finset_sum [AddCommMonoid M] (s : Finset ι) (f : ι → M) (a : α) :\n single a (∑ b in s, f b) = ∑ b in s, single a (f b) := by\n trans\n · apply single_multiset_sum\n · rw [Multiset.map_map]\n rfl\n#align finsupp.single_finset_sum Finsupp.single_finset_sum\n\ntheorem single_sum [Zero M] [AddCommMonoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :\n single a (s.sum f) = s.sum fun d c => single a (f d c) :=\n single_finset_sum _ _ _\n#align finsupp.single_sum Finsupp.single_sum\n\n@[to_additive]\ntheorem prod_neg_index [AddGroup G] [CommMonoid M] {g : α →₀ G} {h : α → G → M}\n (h0 : ∀ a, h a 0 = 1) : (-g).prod h = g.prod fun a b => h a (-b) :=\n prod_mapRange_index h0\n#align finsupp.prod_neg_index Finsupp.prod_neg_index\n#align finsupp.sum_neg_index Finsupp.sum_neg_index\n\nend Finsupp\n\nnamespace Finsupp\n\ntheorem finset_sum_apply [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) (a : α) :\n (∑ i in S, f i) a = ∑ i in S, f i a :=\n map_sum (applyAddHom a) _ _\n#align finsupp.finset_sum_apply Finsupp.finset_sum_apply\n\n@[simp]\ntheorem sum_apply [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :\n (f.sum g) a₂ = f.sum fun a₁ b => g a₁ b a₂ :=\n finset_sum_apply _ _ _\n#align finsupp.sum_apply Finsupp.sum_apply\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_finset_sum [AddCommMonoid N] (S : Finset ι) (f : ι → α →₀ N) :\n ⇑(∑ i in S, f i) = ∑ i in S, ⇑(f i) :=\n map_sum (coeFnAddHom : (α →₀ N) →+ _) _ _\n#align finsupp.coe_finset_sum Finsupp.coe_finset_sum\n\n-- Porting note: inserted ⇑ on the rhs\ntheorem coe_sum [Zero M] [AddCommMonoid N] (f : α →₀ M) (g : α → M → β →₀ N) :\n ⇑(f.sum g) = f.sum fun a₁ b => ⇑(g a₁ b) :=\n coe_finset_sum _ _\n#align finsupp.coe_sum Finsupp.coe_sum\n\ntheorem support_sum [DecidableEq β] [Zero M] [AddCommMonoid N] {f : α →₀ M} {g : α → M → β →₀ N} :\n (f.sum g).support ⊆ f.support.biUnion fun a => (g a (f a)).support := by\n have : ∀ c, (f.sum fun a b => g a b c) ≠ 0 → ∃ a, f a ≠ 0 ∧ ¬(g a (f a)) c = 0 := fun a₁ h =>\n let ⟨a, ha, ne⟩ := Finset.exists_ne_zero_of_sum_ne_zero h\n ⟨a, mem_support_iff.mp ha, ne⟩\n simpa only [Finset.subset_iff, mem_support_iff, Finset.mem_biUnion, sum_apply, exists_prop]\n#align finsupp.support_sum Finsupp.support_sum\n\ntheorem support_finset_sum [DecidableEq β] [AddCommMonoid M] {s : Finset α} {f : α → β →₀ M} :\n (Finset.sum s f).support ⊆ s.biUnion fun x => (f x).support := by\n rw [← Finset.sup_eq_biUnion]\n induction' s using Finset.cons_induction_on with a s ha ih\n · rfl\n · rw [Finset.sum_cons, Finset.sup_cons]\n exact support_add.trans (Finset.union_subset_union (Finset.Subset.refl _) ih)\n#align finsupp.support_finset_sum Finsupp.support_finset_sum\n\n@[simp]\ntheorem sum_zero [Zero M] [AddCommMonoid N] {f : α →₀ M} : (f.sum fun _ _ => (0 : N)) = 0 :=\n Finset.sum_const_zero\n#align finsupp.sum_zero Finsupp.sum_zero\n\n@[to_additive (attr := simp)]\ntheorem prod_mul [Zero M] [CommMonoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :\n (f.prod fun a b => h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=\n Finset.prod_mul_distrib\n#align finsupp.prod_mul Finsupp.prod_mul\n#align finsupp.sum_add Finsupp.sum_add\n\n@[to_additive (attr := simp)]\ntheorem prod_inv [Zero M] [CommGroup G] {f : α →₀ M} {h : α → M → G} :\n (f.prod fun a b => (h a b)⁻¹) = (f.prod h)⁻¹ :=\n (map_prod (MonoidHom.id G)⁻¹ _ _).symm\n#align finsupp.prod_inv Finsupp.prod_inv\n#align finsupp.sum_neg Finsupp.sum_neg\n\n@[simp]\ntheorem sum_sub [Zero M] [AddCommGroup G] {f : α →₀ M} {h₁ h₂ : α → M → G} :\n (f.sum fun a b => h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=\n Finset.sum_sub_distrib\n#align finsupp.sum_sub Finsupp.sum_sub\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism on the support.\nThis is a more general version of `Finsupp.prod_add_index'`; the latter has simpler hypotheses. -/\n@[to_additive\n \"Taking the product under `h` is an additive homomorphism of finsupps, if `h` is an\n additive homomorphism on the support. This is a more general version of\n `Finsupp.sum_add_index'`; the latter has simpler hypotheses.\"]\ntheorem prod_add_index [DecidableEq α] [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n {h : α → M → N} (h_zero : ∀ a ∈ f.support ∪ g.support, h a 0 = 1)\n (h_add : ∀ a ∈ f.support ∪ g.support, ∀ (b₁ b₂), h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n rw [Finsupp.prod_of_support_subset f (subset_union_left _ g.support) h h_zero,\n Finsupp.prod_of_support_subset g (subset_union_right f.support _) h h_zero, ←\n Finset.prod_mul_distrib, Finsupp.prod_of_support_subset (f + g) Finsupp.support_add h h_zero]\n exact Finset.prod_congr rfl fun x hx => by apply h_add x hx\n#align finsupp.prod_add_index Finsupp.prod_add_index\n#align finsupp.sum_add_index Finsupp.sum_add_index\n\n/-- Taking the product under `h` is an additive-to-multiplicative homomorphism of finsupps,\nif `h` is an additive-to-multiplicative homomorphism.\nThis is a more specialized version of `Finsupp.prod_add_index` with simpler hypotheses. -/\n@[to_additive\n \"Taking the sum under `h` is an additive homomorphism of finsupps,if `h` is an additive\n homomorphism. This is a more specific version of `finsupp.sum_add_index` with simpler\n hypotheses.\"]\ntheorem prod_add_index' [AddZeroClass M] [CommMonoid N] {f g : α →₀ M} {h : α → M → N}\n (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f + g).prod h = f.prod h * g.prod h := by\n classical exact prod_add_index (fun a _ => h_zero a) fun a _ => h_add a\n#align finsupp.prod_add_index' Finsupp.prod_add_index'\n#align finsupp.sum_add_index' Finsupp.sum_add_index'\n\n@[simp]\ntheorem sum_hom_add_index [AddZeroClass M] [AddCommMonoid N] {f g : α →₀ M} (h : α → M →+ N) :\n ((f + g).sum fun x => h x) = (f.sum fun x => h x) + g.sum fun x => h x :=\n sum_add_index' (fun a => (h a).map_zero) fun a => (h a).map_add\n#align finsupp.sum_hom_add_index Finsupp.sum_hom_add_index\n\n@[simp]\ntheorem prod_hom_add_index [AddZeroClass M] [CommMonoid N] {f g : α →₀ M}\n (h : α → Multiplicative M →* N) :\n ((f + g).prod fun a b => h a (Multiplicative.ofAdd b)) =\n (f.prod fun a b => h a (Multiplicative.ofAdd b)) *\n g.prod fun a b => h a (Multiplicative.ofAdd b) :=\n prod_add_index' (fun a => (h a).map_one) fun a => (h a).map_mul\n#align finsupp.prod_hom_add_index Finsupp.prod_hom_add_index\n\n/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`\nand monoid homomorphisms `(α →₀ M) →+ N`. -/\ndef liftAddHom [AddZeroClass M] [AddCommMonoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N)\n where\n toFun F :=\n { toFun := fun f ↦ f.sum fun x ↦ F x\n map_zero' := Finset.sum_empty\n map_add' := fun _ _ => sum_add_index' (fun x => (F x).map_zero) fun x => (F x).map_add }\n invFun F x := F.comp (singleAddHom x)\n left_inv F := by\n ext\n simp [singleAddHom]\n right_inv F := by\n -- Porting note: This was `ext` and used the wrong lemma\n apply Finsupp.addHom_ext'\n simp [singleAddHom, AddMonoidHom.comp, Function.comp]\n map_add' F G := by\n ext x\n exact sum_add\n#align finsupp.lift_add_hom Finsupp.liftAddHom\n\n@[simp]\ntheorem liftAddHom_apply [AddCommMonoid M] [AddCommMonoid N] (F : α → M →+ N) (f : α →₀ M) :\n (liftAddHom (α := α) (M := M) (N := N)) F f = f.sum fun x => F x :=\n rfl\n#align finsupp.lift_add_hom_apply Finsupp.liftAddHom_apply\n\n@[simp]\ntheorem liftAddHom_symm_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α) :\n (liftAddHom (α := α) (M := M) (N := N)).symm F x = F.comp (singleAddHom x) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply Finsupp.liftAddHom_symm_apply\n\ntheorem liftAddHom_symm_apply_apply [AddCommMonoid M] [AddCommMonoid N] (F : (α →₀ M) →+ N) (x : α)\n (y : M) : (liftAddHom (α := α) (M := M) (N := N)).symm F x y = F (single x y) :=\n rfl\n#align finsupp.lift_add_hom_symm_apply_apply Finsupp.liftAddHom_symm_apply_apply\n\n@[simp]\ntheorem liftAddHom_singleAddHom [AddCommMonoid M] :\n (liftAddHom (α := α) (M := M) (N := α →₀ M)) (singleAddHom : α → M →+ α →₀ M) =\n AddMonoidHom.id _ :=\n liftAddHom.toEquiv.apply_eq_iff_eq_symm_apply.2 rfl\n#align finsupp.lift_add_hom_single_add_hom Finsupp.liftAddHom_singleAddHom\n\n@[simp]\ntheorem sum_single [AddCommMonoid M] (f : α →₀ M) : f.sum single = f :=\n FunLike.congr_fun liftAddHom_singleAddHom f\n#align finsupp.sum_single Finsupp.sum_single\n\n/-- The `Finsupp` version of `Finset.univ_sum_single` -/\n@[simp]\ntheorem univ_sum_single [Fintype α] [AddCommMonoid M] (f : α →₀ M) :\n ∑ a : α, single a (f a) = f := by\n classical\n refine FunLike.coe_injective ?_\n simp_rw [coe_finset_sum, single_eq_pi_single, Finset.univ_sum_single]\n\n@[simp]\ntheorem univ_sum_single_apply [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single i m j = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n classical rw [single, coe_mk, Finset.sum_pi_single']\n simp\n#align finsupp.sum_univ_single Finsupp.univ_sum_single_apply\n\n@[simp]\ntheorem univ_sum_single_apply' [AddCommMonoid M] [Fintype α] (i : α) (m : M) :\n ∑ j : α, single j m i = m := by\n -- Porting note: rewrite due to leaky classical in lean3\n simp_rw [single, coe_mk]\n classical rw [Finset.sum_pi_single]\n simp\n#align finsupp.sum_univ_single' Finsupp.univ_sum_single_apply'\n\n\ntheorem equivFunOnFinite_symm_eq_sum [Fintype α] [AddCommMonoid M] (f : α → M) :\n equivFunOnFinite.symm f = ∑ a, Finsupp.single a (f a) := by\n rw [← univ_sum_single (equivFunOnFinite.symm f)]\n ext\n simp\n\n-- Porting note: simp can prove this\n-- @[simp]\ntheorem liftAddHom_apply_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α)\n (b : M) : (liftAddHom (α := α) (M := M) (N := N)) f (single a b) = f a b :=\n sum_single_index (f a).map_zero\n#align finsupp.lift_add_hom_apply_single Finsupp.liftAddHom_apply_single\n\n@[simp]\ntheorem liftAddHom_comp_single [AddCommMonoid M] [AddCommMonoid N] (f : α → M →+ N) (a : α) :\n ((liftAddHom (α := α) (M := M) (N := N)) f).comp (singleAddHom a) = f a :=\n AddMonoidHom.ext fun b => liftAddHom_apply_single f a b\n#align finsupp.lift_add_hom_comp_single Finsupp.liftAddHom_comp_single\n\ntheorem comp_liftAddHom [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] (g : N →+ P)\n (f : α → M →+ N) :\n g.comp ((liftAddHom (α := α) (M := M) (N := N)) f) =\n (liftAddHom (α := α) (M := M) (N := P)) fun a => g.comp (f a) :=\n liftAddHom.symm_apply_eq.1 <|\n funext fun a => by\n rw [liftAddHom_symm_apply]\n rw [AddMonoidHom.comp_assoc]\n rw [liftAddHom_comp_single]\n#align finsupp.comp_lift_add_hom Finsupp.comp_liftAddHom\n\ntheorem sum_sub_index [AddCommGroup β] [AddCommGroup γ] {f g : α →₀ β} {h : α → β → γ}\n (h_sub : ∀ a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) : (f - g).sum h = f.sum h - g.sum h :=\n ((liftAddHom (α := α) (M := β) (N := γ)) fun a =>\n AddMonoidHom.ofMapSub (h a) (h_sub a)).map_sub f g\n#align finsupp.sum_sub_index Finsupp.sum_sub_index\n\n@[to_additive]\ntheorem prod_embDomain [Zero M] [CommMonoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :\n (v.embDomain f).prod g = v.prod fun a b => g (f a) b := by\n rw [prod]\n rw [prod]\n rw [support_embDomain]\n rw [Finset.prod_map]\n simp_rw [embDomain_apply]\n#align finsupp.prod_emb_domain Finsupp.prod_embDomain\n#align finsupp.sum_emb_domain Finsupp.sum_embDomain\n\n@[to_additive]\ntheorem prod_finset_sum_index [AddCommMonoid M] [CommMonoid N] {s : Finset ι} {g : ι → α →₀ M}\n {h : α → M → N} (h_zero : ∀ a, h a 0 = 1) (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (∏ i in s, (g i).prod h) = (∑ i in s, g i).prod h :=\n Finset.cons_induction_on s rfl fun a s has ih => by\n rw [prod_cons]\n rw [ih]\n rw [sum_cons]\n rw [prod_add_index' h_zero h_add]\n#align finsupp.prod_finset_sum_index Finsupp.prod_finset_sum_index\n#align finsupp.sum_finset_sum_index Finsupp.sum_finset_sum_index\n\n@[to_additive]\ntheorem prod_sum_index [AddCommMonoid M] [AddCommMonoid N] [CommMonoid P] {f : α →₀ M}\n {g : α → M → β →₀ N} {h : β → N → P} (h_zero : ∀ a, h a 0 = 1)\n (h_add : ∀ a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :\n (f.sum g).prod h = f.prod fun a b => (g a b).prod h :=\n (prod_finset_sum_index h_zero h_add).symm\n#align finsupp.prod_sum_index Finsupp.prod_sum_index\n#align finsupp.sum_sum_index Finsupp.sum_sum_index\n\ntheorem multiset_sum_sum_index [AddCommMonoid M] [AddCommMonoid N] (f : Multiset (α →₀ M))\n (h : α → M → N) (h₀ : ∀ a, h a 0 = 0)\n (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :\n f.sum.sum h = (f.map fun g : α →₀ M => g.sum h).sum :=\n Multiset.induction_on f rfl fun a s ih => by\n rw [Multiset.sum_cons]\n rw [Multiset.map_cons]\n rw [Multiset.sum_cons]\n rw [sum_add_index' h₀ h₁]\n rw [ih]\n#align finsupp.multiset_sum_sum_index Finsupp.multiset_sum_sum_index\n\ntheorem support_sum_eq_biUnion {α : Type*} {ι : Type*} {M : Type*} [DecidableEq α]\n [AddCommMonoid M] {g : ι → α →₀ M} (s : Finset ι)\n (h : ∀ i₁ i₂, i₁ ≠ i₂ → Disjoint (g i₁).support (g i₂).support) :\n (∑ i in s, g i).support = s.biUnion fun i => (g i).support := by\n classical\n -- Porting note: apply Finset.induction_on s was not working; refine does.\n refine Finset.induction_on s ?_ ?_\n · simp\n · intro i s hi\n simp only [hi, sum_insert, not_false_iff, biUnion_insert]\n intro hs\n rw [Finsupp.support_add_eq]\n rw [hs]\n rw [hs]\n rw [Finset.disjoint_biUnion_right]\n intro j hj\n refine' h _ _ (ne_of_mem_of_not_mem hj hi).symm\n#align finsupp.support_sum_eq_bUnion Finsupp.support_sum_eq_biUnion\n\ntheorem multiset_map_sum [Zero M] {f : α →₀ M} {m : β → γ} {h : α → M → Multiset β} :\n Multiset.map m (f.sum h) = f.sum fun a b => (h a b).map m :=\n map_sum (Multiset.mapAddMonoidHom m) _ f.support\n#align finsupp.multiset_map_sum Finsupp.multiset_map_sum\n\ntheorem multiset_sum_sum [Zero M] [AddCommMonoid N] {f : α →₀ M} {h : α → M → Multiset N} :\n Multiset.sum (f.sum h) = f.sum fun a b => Multiset.sum (h a b) :=\n map_sum Multiset.sumAddMonoidHom _ f.support\n#align finsupp.multiset_sum_sum Finsupp.multiset_sum_sum\n\n/-- For disjoint `f1` and `f2`, and function `g`, the product of the products of `g`\nover `f1` and `f2` equals the product of `g` over `f1 + f2` -/\n@[to_additive\n \"For disjoint `f1` and `f2`, and function `g`, the sum of the sums of `g`\n over `f1` and `f2` equals the sum of `g` over `f1 + f2`\"]\ntheorem prod_add_index_of_disjoint [AddCommMonoid M] {f1 f2 : α →₀ M}\n (hd : Disjoint f1.support f2.support) {β : Type*} [CommMonoid β] (g : α → M → β) :\n (f1 + f2).prod g = f1.prod g * f2.prod g := by\n have :\n ∀ {f1 f2 : α →₀ M},\n Disjoint f1.support f2.support → (∏ x in f1.support, g x (f1 x + f2 x)) = f1.prod g :=\n fun hd =>\n Finset.prod_congr rfl fun x hx => by\n simp only [not_mem_support_iff.mp (disjoint_left.mp hd hx), add_zero]\n classical simp_rw [← this hd, ← this hd.symm, add_comm (f2 _), Finsupp.prod, support_add_eq hd,\n prod_union hd, add_apply]\n#align finsupp.prod_add_index_of_disjoint Finsupp.prod_add_index_of_disjoint\n#align finsupp.sum_add_index_of_disjoint Finsupp.sum_add_index_of_disjoint\n\ntheorem prod_dvd_prod_of_subset_of_dvd [AddCommMonoid M] [CommMonoid N] {f1 f2 : α →₀ M}\n {g1 g2 : α → M → N} (h1 : f1.support ⊆ f2.support)\n (h2 : ∀ a : α, a ∈ f1.support → g1 a (f1 a) ∣ g2 a (f2 a)) : f1.prod g1 ∣ f2.prod g2 := by\n classical\n simp only [Finsupp.prod, Finsupp.prod_mul]\n rw [← sdiff_union_of_subset h1]\n rw [prod_union sdiff_disjoint]\n apply dvd_mul_of_dvd_right\n apply prod_dvd_prod_of_dvd\n exact h2\n#align finsupp.prod_dvd_prod_of_subset_of_dvd Finsupp.prod_dvd_prod_of_subset_of_dvd\n\nlemma indicator_eq_sum_attach_single [AddCommMonoid M] {s : Finset α} (f : ∀ a ∈ s, M) :\n indicator s f = ∑ x in s.attach, single ↑x (f x x.2) := by\n rw [← sum_single (indicator s f)]\n rw [sum]\n rw [sum_subset (support_indicator_subset _ _)]\n rw [← sum_attach]\n · refine' Finset.sum_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n · intro i _ hi\n rw [not_mem_support_iff.mp hi]\n rw [single_zero]\n#align finsupp.indicator_eq_sum_single Finsupp.indicator_eq_sum_attach_single\n\nlemma indicator_eq_sum_single [AddCommMonoid M] (s : Finset α) (f : α → M) :\n indicator s (fun x _ ↦ f x) = ∑ x in s, single x (f x) :=\n (indicator_eq_sum_attach_single _).trans <| sum_attach (f := fun x ↦ single x (f x))\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index_eq_prod_attach [Zero M] [CommMonoid N]\n {s : Finset α} (f : ∀ a ∈ s, M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s f).prod h = ∏ x in s.attach, h ↑x (f x x.2) := by\n rw [prod_of_support_subset _ (support_indicator_subset _ _) h h_zero]\n rw [← prod_attach]\n refine' Finset.prod_congr rfl (fun _ _ => _)\n rw [indicator_of_mem]\n#align finsupp.prod_indicator_index Finsupp.prod_indicator_index_eq_prod_attach\n#align finsupp.sum_indicator_index Finsupp.sum_indicator_index_eq_sum_attach\n\n@[to_additive (attr := simp)]\nlemma prod_indicator_index [Zero M] [CommMonoid N]\n {s : Finset α} (f : α → M) {h : α → M → N} (h_zero : ∀ a ∈ s, h a 0 = 1) :\n (indicator s (fun x _ ↦ f x)).prod h = ∏ x in s, h x (f x) :=\n (prod_indicator_index_eq_prod_attach _ h_zero).trans <| prod_attach (f := fun x ↦ h x (f x))\n\nlemma sum_cons [AddCommMonoid M] (n : ℕ) (σ : Fin n →₀ M) (i : M) :\n (sum (cons i σ) fun _ e ↦ e) = i + sum σ (fun _ e ↦ e) := by\n rw [sum_fintype _ _ (fun _ => rfl)]\n rw [sum_fintype _ _ (fun _ => rfl)]\n exact Fin.sum_cons i σ\n\nlemma sum_cons' [AddCommMonoid M] [AddCommMonoid N] (n : ℕ) (σ : Fin n →₀ M) (i : M)\n (f : Fin (n+1) → M → N) (h : ∀ x, f x 0 = 0) :\n (sum (Finsupp.cons i σ) f) = f 0 i + sum σ (Fin.tail f) := by\n rw [sum_fintype _ _ (fun _ => by apply h), sum_fintype _ _ (fun _ => by apply h)]\n simp_rw [Fin.sum_univ_succ, cons_zero, cons_succ]\n congr\n\nend Finsupp\n\ntheorem Finset.sum_apply' : (∑ k in s, f k) i = ∑ k in s, f k i :=\n map_sum (Finsupp.applyAddHom i) f s\n#align finset.sum_apply' Finset.sum_apply'\n\ntheorem Finsupp.sum_apply' : g.sum k x = g.sum fun i b => k i b x :=\n Finset.sum_apply _ _ _\n#align finsupp.sum_apply' Finsupp.sum_apply'\n\nsection\n\nopen Classical\n\ntheorem Finsupp.sum_sum_index' : (∑ x in s, f x).sum t = ∑ x in s, (f x).sum t :=\n Finset.induction_on s rfl fun a s has ih => by\n simp_rw [Finset.sum_insert has, Finsupp.sum_add_index' h0 h1, ih]\n#align finsupp.sum_sum_index' Finsupp.sum_sum_index'\n\nend\n\nsection\n\nvariable [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S]\n\ntheorem Finsupp.sum_mul (b : S) (s : α →₀ R) {f : α → R → S} :\n s.sum f * b = s.sum fun a c => f a c * b := by simp only [Finsupp.sum, Finset.sum_mul]\n#align finsupp.sum_mul Finsupp.sum_mul\n\ntheorem Finsupp.mul_sum (b : S) (s : α →₀ R) {f : α → R → S} :\n b * s.sum f = s.sum fun a c => b * f a c := by simp only [Finsupp.sum, Finset.mul_sum]\n#align finsupp.mul_sum Finsupp.mul_sum\n\nend\n\nnamespace Nat\n\n-- Porting note: Needed to replace pow with (· ^ ·)\n/-- If `0 : ℕ` is not in the support of `f : ℕ →₀ ℕ` then `0 < ∏ x in f.support, x ^ (f x)`. -/\ntheorem prod_pow_pos_of_zero_not_mem_support {f : ℕ →₀ ℕ} (hf : 0 ∉ f.support) :\n 0 < f.prod (· ^ ·) :=\n Finset.prod_pos fun a ha => pos_iff_ne_zero.mpr (pow_ne_zero _ fun H => by subst H; ","nextTactic":"exact hf ha","declUpToTactic":"/-- If `0 : ℕ` is not in the support of `f : ℕ →₀ ℕ` then `0 < ∏ x in f.support, x ^ (f x)`. -/\ntheorem prod_pow_pos_of_zero_not_mem_support {f : ℕ →₀ ℕ} (hf : 0 ∉ f.support) :\n 0 < f.prod (· ^ ·) :=\n Finset.prod_pos fun a ha => pos_iff_ne_zero.mpr (pow_ne_zero _ fun H => by subst H; ","declId":"Examples.Mathlib.SplitRw.Mathlib_Algebra_BigOperators_Finsupp.741_0.MEVUz78Vsm81fPx","decl":"/-- If `0 : ℕ` is not in the support of `f : ℕ →₀ ℕ` then `0 < ∏ x in f.support, x ^ (f x)`. -/\ntheorem prod_pow_pos_of_zero_not_mem_support {f : ℕ →₀ ℕ} (hf : 0 ∉ f.support) :\n 0 < f.prod (· ^ ·) "}